我有一个页面,用户滚动和动画在页面上可见时显示,当它们不可见时隐藏。每当滚动页面时都会发生这种情况,但它似乎占用了太多的处理能力并且页面滚动相当静态。
这是我正在使用的代码:
$('body').scroll(function(){
$('.anim').on('inview', function (event, visible) {
if (visible == true) {
// element is now visible in the viewport
$(this).removeClass("hidden");
$(this).addClass("visible animated fadeIn");
} else {
// element has gone out of viewport
$(this).removeClass("visible animated fadeIn");
$(this).addClass("hidden");
}
});
$('.anim_bounceIn').on('inview', function (event, visible) {
if (visible == true) {
// element is now visible in the viewport
$(this).removeClass("hidden");
$(this).addClass("visible animated bounceIn");
} else {
// element has gone out of viewport
$(this).removeClass("visible animated bounceIn");
$(this).addClass("hidden");
}
});
$('.anim_bounceInUp').on('inview', function (event, visible) {
if (visible == true) {
// element is now visible in the viewport
$("#"+$(this).attr("relID")).removeClass("hidden");
$("#"+$(this).attr("relID")).addClass("visible animated bounceInUp");
} else {
// element has gone out of viewport
$("#"+$(this).attr("relID")).removeClass("visible animated bounceInUp");
$("#"+$(this).attr("relID")).addClass("hidden");
}
});
});
据我所知,滚动触发功能不是很有效。有没有更好的方法让我做到这一点?
这是有问题的页面,它只是一个测试区域......