[英]Positioning div to top of viewport using jQuery
How do I position the #lightbox div to always be at the top of the viewport? 如何将#lightbox div始终置于视口的顶部?
$(document).ready(function(){
$('.mehr').click(function() {
$("body").css("overflow", "hidden");
$('#lightbox').css({'visibility' : 'visible'}).animate({'background-color': 'rgba(0, 0, 0, 0.9)', 'opacity': '1'}, 500);
});
Many thanks for any help! 非常感谢您的帮助!
CSS : CSS:
#lightbox {
position: absolute;
z-index: 999;
}
设定position:absolute
和z-index:1000
position: fixed; top:0; z-index:999999;
You can use this with simple HTML / CSS : http://jsfiddle.net/wZDXg/ 您可以将其与简单的HTML / CSS一起使用: http : //jsfiddle.net/wZDXg/
HTML: HTML:
<div id="lightbox">Light box</div>
<div id="other">Other content</div>
CSS: CSS:
body
{
margin:0;
}
#lightbox
{
background-color:gray;
width : 100%;
height: 150px;
position : fixed;
top : 0;
margin-bottom:150px;
}
#other
{
margin-top : 150px;
height : 1500px;
background-color:#999999;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.