JQ實現彈出層效果


html代碼
  <
div id="layer"></div> <div class="text"> <a href="javascript:showlayer()">click here show layer</a> <div id="pop">O(∩_∩)O~ &nbsp;&nbsp;&nbsp;I am pop layer.</div> </div>
css樣式
     body
{ font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:0px; padding:0px; } .text{ width:100%; font-size: 20px; color: #000; text-align: center; padding-top: 200px; } a{ color: #000; text-decoration: none; } #layer{ background-color:gray; left:0; opacity:0.5; position:absolute; top:0; z-index:3; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity:0.5; } #pop{ text-align:center; background-color:#fff; height:200px; left:50%; margin:-200px 0 0 -200px; padding:1px; position:fixed; position:absolute; top:50%; width:360px; z-index:5; border-radius:6px; display:none; line-height: 200px; }
    
JS部分

    //show layer function showlayer(){ var bh=$(window).height();//獲取屏幕高度 var bw=$(window).width();//獲取屏幕寬度 $("#layer").css({ height:bh, width:bw, display:"block" }); $("#pop").show(); } //close layer $("#pop").click(function(){ $("#layer,#pop").hide(); }) $("#layer").click(function(){ $("#layer,#pop").hide(); })

  遮罩層的思路:取屏幕的寬高,賦值給遮罩層。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM