我希望在我的网站上滚动时固定标题和导航栏。我可以将它们都修复,但是 #container div 中的内容不会出现在它们下面。
我目前使用以下方法使我的网站内容显示在标题下方,但不确定如何计算 #header 和 #navbar id 的 margintop。
#header{
width:100%;
position:fixed;
top:0px;
}
#navbar{
width:100%;
height:50px;
margin:auto;
position:fixed;
top:120px;
}
$(document).ready(function () {
$('#container').css('marginTop', $('#header').outerHeight(true) );
});
感谢您的帮助。
最佳答案
$(document).ready(function () { $('#container').css('marginTop', $('#header').outerHeight(true) + $('#navbar').outerHeight(true) ); });
关于javascript - 滚动时固定标题和导航栏下的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15718456/