jquery弹出遮罩层(可随滚动条而移动的)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/jquery_last.js" charset="UTF-8"></script>
<script type="text/javascript"> 
$(function(){ 
    var mask = $(".mask"); 
    var box = $(".box"); 
    $(".link").click(function(){ 
        mask.show(); 
        box.show(); 
        MaskAdapt(); 
        BoxAdapt(); 
    }); 
    $("#closed").click(function(){ 
        mask.hide(); 
        box.hide(); 
    }); 
    mask.click(function(){ 
        mask.hide(); 
        box.hide(); 
    }); 
    $(window).scroll(function(){ 
        BoxAdapt(); 
    }); 
    $(window).resize(function(){ 
        BoxAdapt(); 
        MaskAdapt(); 
    }); 
}); 
function MaskAdapt(){ 
    var docWidth = $(document.body).outerWidth(true); 
    var docHeight = $(document).height(); 
    $(".mask").height(docHeight).width(docWidth); 
}; 
function BoxAdapt(){ 
    var winWidth = $(window).width(); 
    var winHeight = $(window).height(); 
    var scrHeight = $(document).scrollTop(); 
    var boxHeight = $(".box").height(); 
    var boxWidth = $(".box").width(); 
    var centerWidth = (winWidth-boxWidth)/2 
    var centerHeight = (winHeight-boxHeight)/2+scrHeight 
    var offsetHeight = $(".box").offset().top; 
    if(offsetHeight <  centerHeight){ 
    //如果想不要跳动效果,就把前面的animate去掉,最后一个animate中100改为0
        $(".box").css("left",centerWidth).stop(true,false).animate({"top":centerHeight*1.1,"left":centerWidth},300).animate({"top":centerHeight*0.95,"left":centerWidth},200).animate({"top":centerHeight,"left":centerWidth},100); 
    }else{ 
        $(".box").css("left",centerWidth).stop(true,false).animate({"top":centerHeight*0.8,"left":centerWidth},300).animate({"top":centerHeight*1.05,"left":centerWidth},200).animate({"top":centerHeight,"left":centerWidth},100); 
    }; 
}; 
</script> 
<style type="text/css"> 

.mask {position:absolute; left:0; top:0; width:100%; height:100%; background:#000; opacity:0.6;filter:alpha(opacity=60); display:none; z-index:998;} 
.box {position:absolute; top:0; left:50%; width:400px; height:200px; background:#993; z-index:999; display:none; padding:20px;} 
</style> 
<body>
<div style="height:3000px;padding:200px;"> 
    <a class="link" href="javascript:void(0)">Click here</a> 
    <div class="mask"></div> 
    <div class="box"><p>I'm dialog box to pop up</p><p>I how so the tragedy, is people pop up</p><p>In fact it, I'll immortals mode</p><input id="closed" type="button" value="close" /></div> 
</div> 
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值