当我按“点击我”时,会出现弹出式div infobox
。位于bg
div后面的infobox
div应该覆盖页面的100%,发生的事情是它只覆盖100%的窗口。我该如何解决这个问题?这是jsfiddle http://jsfiddle.net/mdanz/wWLVr/2/
<html>
<head>
<style type="text/css">
#infobox {
position:absolute; width:100px; height:150px; top:100px; left:50%; z-index:2; margin-left:-50px; display:none; border:1px solid black; background-color:#FFFFFF;
}
#bg {
position:absolute; background-color:#000000; opacity:0.4; filter:alpha(opacity=40); top:0; left:0; width:100%; display:none; min-height:100%; z-index:1;
}
.displaybox {
display:block; border:1px solid black; background-color:green; width:200px; height:200px;
}
#infobutton {
border:1px solid black; width:100px; padding:5px; display:block; cursor:pointer;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('#infobutton').click(function() {
$('#bg').show();
$('#infobox').show();
$('html, body').animate({ scrollTop: 0 }, 0);
});
});
</script>
</head>
<body>
<div id='infobutton'>Click Me</div>
<div id='bg'></div>
<div id='infobox'></div>
<div class='displaybox'></div>
<div class='displaybox'></div>
<div class='displaybox'></div>
<div class='displaybox'></div>
<div class='displaybox'></div>
<div class='displaybox'></div>
</body>
</html>
答案 0 :(得分:1)
您可以添加:
$('#bg').css("height", $("body").css("height"));
在显示此元素之前......
你可以看看这个小提琴:http://jsfiddle.net/scaillerie/uWeJf/