| JS彈窗 JS彈出DIV并使整個(gè)頁(yè)面背景變暗功能的實(shí)現(xiàn)代碼  更新時(shí)間:2018年04月21日 14:05:35   作者:下頁(yè)、再停留      我要評(píng)論這篇文章主要介紹了JS彈窗 JS彈出DIV并使整個(gè)頁(yè)面背景變暗功能的實(shí)現(xiàn)代碼,需要的朋友可以參考下
            1.首先寫(xiě)一個(gè)遮罩層div,然后再寫(xiě)一個(gè)彈窗的div 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <!-- 遮罩層 -->
 <div id="cover"style="background: #000; position: absolute; left: 0px; top: 0px; width: 100%; filter: alpha(opacity=30); opacity: 0.3; display: none; z-index: 2 ">
   
 </div>
 <!-- 彈窗 -->
 <div id="showdiv"style="width: 80%; margin: 0 auto; height: 9.5rem; border: 1px solid #999; display: none; position: absolute; top: 40%; left: 10%; z-index: 3; background: #fff">
   <!-- 標(biāo)題 -->
   <div style="background: #F8F7F7; width: 100%; height: 2rem; font-size: 0.65rem; line-height: 2rem; border: 1px solid #999; text-align: center;">
     提示
   </div>
   <!-- 內(nèi)容 -->
   <div style="text-indent: 50px; height: 4rem; font-size: 0.5rem; padding: 0.5rem; line-height: 1rem; ">
     js彈窗 js彈出DIV,并使整個(gè)頁(yè)面背景變暗</div>
   <!-- 按鈕 -->
   <div style="background: #418BCA; width: 80%; margin: 0 auto; height: 1.5rem; line-height: 1.5rem; text-align: center;color: #fff;margin-top: 1rem; -moz-border-radius: .128rem; -webkit-border-radius: .128rem; border-radius: .128rem;font-size: .59733rem;"onclick="closeWindow()">
     確 定
   </div>
 </div>
 | 
 js代碼:(把jq引進(jìn)來(lái)) 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | <script type="text/javascript">
   // 彈窗
   functionshowWindow() {
     $('#showdiv').show();  //顯示彈窗
     $('#cover').css('display','block'); //顯示遮罩層
     $('#cover').css('height',document.body.clientHeight+'px'); //設(shè)置遮罩層的高度為當(dāng)前頁(yè)面高度
   }
   // 關(guān)閉彈窗
   functioncloseWindow() {
     $('#showdiv').hide();  //隱藏彈窗
     $('#cover').css('display','none');   //顯示遮罩層
   }
 </script>
 | 
 效果:
 
 總結(jié) 以上所述是小編給大家介紹的JS彈窗 JS彈出DIV并使整個(gè)頁(yè)面背景變暗功能的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的! |