【发布时间】:2015-10-31 13:10:15
【问题描述】:
每当这些元素进入视野时,我都会尝试使用“fade-me”类淡入元素。我找到了这个小提琴:http://jsfiddle.net/tcloninger/e5qad/,它确实做到了这一点,但是它重复地将不透明度值添加到出现的元素中。如果我尝试使用 Velocity 的过渡 slideUpIn 而不是不透明度,这将创建一个循环动画。所以我有以下代码:
$(document).ready(function() {
/* Every time the window is scrolled ... */
$(window).scroll( function(){
/* Check the location of each desired element */
$('.hideme').each( function(i){
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, fade it it */
if( bottom_of_window > bottom_of_object ){
$(this).velocity('transition.slideUpIn', { stagger: 700 }).delay(1000)
}
});
});
});
它可以工作,但它会循环 SlideUpIn 动画。如何让它在出现的那个元素上只运行一次动画?
【问题讨论】:
标签: javascript jquery html velocity.js