仅当滚动达到某个点时,您可以将其位置固定:
$(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
}
});
Run Code Online (Sandbox Code Playgroud)
div 的 CSS 如下:
#tester {
position: absolute;
right: 20px;
top: 200px;
height: 200px;
width: 100px;
background: red;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10699 次 |
| 最近记录: |