【发布时间】:2016-04-02 11:24:12
【问题描述】:
我正在尝试向导航栏添加淡入,因此当我到达某个滚动点时,导航栏会淡入。但是,我的尝试失败了。我尝试将 Jquery 添加到常规 javascript,所以我不确定这是问题所在还是问题所在。我希望导航栏仅在到达导航栏再次出现的页面下方的滚动点时才淡入。
可以在以下位置查看:
http://realtorcatch.com/test_index
我的 Javascript 是:
window.onscroll = function() {
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
if (scrollTop >= document.getElementById("d").offsetTop) {
document.getElementById("header").style.position = "fixed";
document.getElementById("d").style.marginTop = "50px";
document.getElementById("header").style.top = "0";
} else {
$(function() { // $(document).ready shorthand
$('#header').fadeIn('slow');
});
document.getElementById("header").style.position = "static";
document.getElementById("d").style.marginTop = "0px";
document.getElementById("header").style.marginTop = "0px";
}
}
然后我有以下 div,其中包含我的所有代码:
<div id="header">
</div>
【问题讨论】:
标签: javascript jquery html css