更新时间:2022-03-30 00:27:42
Stack: Determine the direction of scroll
使用此功能,然后可以使用.animate
By using this, you can then use .animate
var lastScrollTop = 0;
$("div").scroll(function (event) {
var st = $(this).scrollTop();
if (st > lastScrollTop) {
$('img').animate({top: '-=10'}, 10);
} else {
$('img').animate({top: '+=10'}, 10);
}
lastScrollTop = st;
});
忽略::如果您希望图像随页面一起移动,请将position: fixed;
添加到CSS.
Disregard: If you would like the image to move with the page, add position: fixed;
to the CSS.