jquery實現彈出層完美居中效果 修改版


這個是js文件:

// JavaScript Document
$(document).ready(function(){
    showDiv($("#pop"));
})

function showDiv(obj){
     $(obj).show();
     center(obj);
     $(window).scroll(function(){
      center(obj);
     });
     $(window).resize(function(){
      center(obj);
     });
}
    
function center(obj){
    var windowWidth = document.documentElement.clientWidth;   
    var windowHeight = document.documentElement.clientHeight;   
    var popupHeight = $(obj).height();   
    var popupWidth = $(obj).width();    
    $(obj).css({   
    "position": "absolute",   
    "top": (windowHeight-popupHeight)/2+$(document).scrollTop(),   
    "left": (windowWidth-popupWidth)/2   
    });
}

function deldiv(){
        $("#pop").remove();
    } //點擊刪除層;

全文:http://www.poluoluo.com/jzxy/201403/264802.html

在html代碼中添加:

<div id="pop" style=" position:absolute;left:50%;">
    <div style=" position:absolute; right:5px; bottom:5px; width:200px; height:30px; background:#000000; color:#FF0000; text-align:center; padding-top:10px; font-weight:bold;">點擊關閉</div>
    <a href="javascript:void(0);" onclick="deldiv();"><img src="123.jpg" /></a>
</div>


免責聲明!

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



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