jquery 为多个元素滚动添加类
jquery addclass on scroll for multiple elements
我试图让元素在您向下滚动时淡入。我希望它们在我向下滚动到 div 开始的那一点时出现,我得到了第二个横幅,但第三个横幅内容不会淡入。另外,即使第二个横幅代码有效,应该有更好的方法来做到这一点,也许是可重用的。我就是想不通。任何帮助将不胜感激。
$(window).on('scroll', function() {
if($(this).scrollTop() > 100) {
$('.second-banner-content').addClass('animated fadeInUp slow');
$('.second-banner-img').addClass('animated fadeInUp slow');
}
});
$(window).on('scroll', function() {
if($(this).scrollTop() > 300) {
$('.third-banner-content').addClass('animated fadeIn slow');
}
});
您可以为此使用 AOS 之类的插件,或者您可以计算高度并尝试类似这样的操作
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window > bottom_of_object ){
$(this).addClass('animated fadeInUp slow');
}
我试图让元素在您向下滚动时淡入。我希望它们在我向下滚动到 div 开始的那一点时出现,我得到了第二个横幅,但第三个横幅内容不会淡入。另外,即使第二个横幅代码有效,应该有更好的方法来做到这一点,也许是可重用的。我就是想不通。任何帮助将不胜感激。
$(window).on('scroll', function() {
if($(this).scrollTop() > 100) {
$('.second-banner-content').addClass('animated fadeInUp slow');
$('.second-banner-img').addClass('animated fadeInUp slow');
}
});
$(window).on('scroll', function() {
if($(this).scrollTop() > 300) {
$('.third-banner-content').addClass('animated fadeIn slow');
}
});
您可以为此使用 AOS 之类的插件,或者您可以计算高度并尝试类似这样的操作
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window > bottom_of_object ){
$(this).addClass('animated fadeInUp slow');
}