首頁  >  文章  >  web前端  >  jQuery實現彈跳窗效果(附程式碼)

jQuery實現彈跳窗效果(附程式碼)

php中世界最好的语言
php中世界最好的语言原創
2018-04-23 11:09:583840瀏覽

這次帶給大家jQuery實現彈跳窗效果(附程式碼),jQuery實現彈跳窗效果的注意事項有哪些,下面就是實戰案例,一起來看一下。

這裡利用jquery實現兩種彈窗效果:

1. 淡入彈窗效果:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>www.jb51.net jQuery弹窗</title>
    <style>
      *{padding: 0;margin: 0;}
      .box{width: 100%;height: 100%;}
      .main{width: 100%;height: 100%;background-color: rgba(0,0,0,0.8);display: none;position: fixed;z-index: 1;}
      .mainbox{width: 800px;height: 100%;margin: 0 auto;background-color: rgba(255,255,255,0.8);padding: 20px;}
      .kkk{width: 100%;height: 1200px;background-color: red;}
      .close{color: red;cursor: pointer;}
    </style>
    <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
    <script>
      $(function(){
        $(".btn").click(function(){
          $(".main").fadeIn();
        });
        $(".close").click(function(){
          $(".main").fadeOut();
        });
      });
    </script>
  </head>
  <body>
    <p class="main">
        <p class="mainbox">
          <p class="close">点击关闭</p>
        </p>
      </p>
    <p class="box">
      <p class="kkk">
        <input class="btn" type="button" value="点击淡入弹窗" />
      </p>
    </p>
  </body>
</html>

運行效果:

2. 滑動彈窗效果:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>www.jb51.net jQuery弹窗</title>
    <style>
      *{padding: 0;margin: 0;}
      .box{width: 100%;height: 100%;}
      .main{width: 100%;height: 100%;background-color: rgba(0,0,0,0.8);display: none;position: fixed;z-index: 1;}
      .mainbox{width: 800px;height: 100%;margin: 0 auto;background-color: rgba(255,255,255,0.8);padding: 20px;display: none;}
      .kkk{width: 100%;height: 1200px;background-color: red;}
      .close{color: red;cursor: pointer;}
    </style>
    <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
    <script>
      $(function(){
        $(".btn").click(function(){
          $(".main").fadeIn();
          $(".mainbox").delay(500).slideDown();
        });
        $(".close").click(function(){
          $(".main").fadeOut();
        });
      });
    </script>
  </head>
  <body>
    <p class="main">
        <p class="mainbox">
          <p class="close">点击关闭</p>
        </p>
      </p>
    <p class="box">
      <p class="kkk">
        <input class="btn" type="button" value="点击淡入弹窗" />
      </p>
    </p>
  </body>
</html>

執行效果:

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

JS陣列方法總結

#js仿jquery步驟詳解

以上是jQuery實現彈跳窗效果(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn