【发布时间】:2021-12-28 23:59:51
【问题描述】:
我有一个文本静态文本元素,当用户滚动超过 600 像素时会发生变化,当用户滚动超过 1400 像素时会再次发生变化
$(window).scroll(function () {
if ($(this).scrollTop() > 600) {
$('.p-circle').html('Text 1');
$('.p-circle-s').html('Text 2');
}
});
$(window).scroll(function () {
if ($(this).scrollTop() > 1400) {
$('.p-circle').html('Text 1 updated');
$('.p-circle-s').html('Text 2 updated');
}
});
我怎样才能为它们制作一个基本的褪色动画,我尝试了下一个变体,但它们效果不佳(它会褪色 2 次)
if (scrollTop > 600 && scrollTop <= 1400) {
$('.p-circle').fadeOut(500, function() {
$(this).text('Text 1').fadeIn(500);
});
$('.p-circle-s').fadeOut(500, function() {
$(this).text('Text 2').fadeIn(500);
});
} else if (scrollTop > 1400 && scrollTop <= 2100) {
$('.p-circle').fadeOut(500, function() {
$(this).text('Text 1 updated').fadeIn(500);
});
$('.p-circle-s').fadeOut(500, function() {
$(this).text('Text 2 Updated').fadeIn(500);
});
}
【问题讨论】:
-
PS:你不需要用两个
$(window).scroll(function () {???? -
@RokoC.Buljan 他们这样做了,它在最后被锁住了。
-
@Travis 鹰眼。错过了
-
@RokoC.Buljan 很好地调用了两个 $(window).scroll 函数,我完全错过了。
标签: javascript jquery