【发布时间】:2026-02-03 23:45:01
【问题描述】:
我有这个代码
$(window).load(function () {
$elem1 = $('#div1');
$elem2 = $('#div2');
var scrollState = 'top';
$(window).scroll(function () {
var scrollPos = $(window).scrollTop();
if ((scrollPos != 0) && (scrollState === 'top')) {
$elem1.stop().animate({
opacity: '1.0'
}, 300);
$elem2.stop().animate({
marginLeft: '50px'
}, 300);
scrollState = 'scrolled';
} else if ((scrollPos === 0) && (scrollState === 'scrolled')) {
$elem1.stop().animate({
opacity: '0.0'
}, 300);
$elem2.stop().animate({
marginLeft: '0px'
}, 300);
scrollState = 'top';
}
});
}); //]]>
当我向下滚动页面时,jquery 会在您开始滚动时立即激活。我希望能够选择在页面激活之前您要走多远。
【问题讨论】:
标签: jquery html scroll jquery-animate