天天看點

前端使用bootstrap和jquery制作彈窗

效果如下:

前端使用bootstrap和jquery制作彈窗

代碼如下:

<!doctype html>
<html>
<head>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
	<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>

<body>
<div class="alert alert-success" id="success-alert">
   <button type="button" class="close" data-dismiss="alert">x</button>
   <strong>成功! </strong> 我的第一個提示彈框.
</div>

<div Style="height:100px">
	<p Style="padding-top:50px">使用bootstrap和jQuery制作彈窗</p>
</div>

<div class="product-options">
	<button id="myWish" class="btn btn-success">點我彈出彈框 </button>
</div>
</body>

<script>
   $(document).ready(function() {
   //沒點選的時候隐藏彈框
   $("#success-alert").hide();
   //點選的時候彈出彈框2秒
   $("#myWish").click(function showAlert() {
      $("#success-alert").fadeTo(2000, 500).slideUp(500, function() {
		$("#success-alert").slideUp(500);
    });
  });
});
</script>
</html>
           

參考:

Bootstrap Alert Auto Close