【发布时间】:2016-01-23 08:25:14
【问题描述】:
先生,我想在向下滚动窗口时将 div id menu 固定在窗口顶部锁定我的菜单,并且我想在向上滚动时将位置设置为绝对位置我尝试使用此代码。它正确地完成了第一份工作。我可以设置固定在页面顶部的菜单。但是向上滚动时无法设置页面绝对位置是我的代码
<script type="application/javascript">
$(window).bind('scroll', function () {
if (window.scrollY=100){
document.getElementById("menu").style.position = "fixed";
document.getElementById("menu").style.top = "0px";
}
else if(window.scrollY < 100){
document.getElementById("menu").style.position = "absolute";
document.getElementById("menu").style.top = "100px";
}
});
</script>
【问题讨论】:
标签: javascript