我有一个客户网站 - www.stagecraft.co.uk,他们想要在租用页面 http://www.stagecraft.co.uk/hire.html (较长的页面 http://www.stagecraft.co.uk/lighting/genericlanterns.html)当您向下滚动页面时仍然存在。我已经快速移动(不是实时),位置固定,但这样做时,左侧导航距离窗口顶部大约 200px 左右。滚动时何时将其置于窗口顶部?
提前致谢....
仅当滚动达到某个点时,您可以将其位置固定:
$(window).scroll(function() {
if ($(this).scrollTop() > 200) { //I just used 200 for testing
$("#tester").css({ "position": "fixed", "top": 0 });
} else {
$("#tester").css({ "position": "absolute", "top": "200px" }); //same here
}
});
div 的 CSS 如下:
#tester {
position: absolute;
right: 20px;
top: 200px;
height: 200px;
width: 100px;
background: red;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)