使用jQuery触发onScroll事件的多个动画

我有一个函数,当滚动到视图时淡出特定的DIV。 我在这些DIV中有一些子元素,我想在每个淡入淡出动画结束时制作动画。 如何在以下function中添加其他function?

$(window).scroll(function(d,h) { tiles.each(function(i) { a = $(this).offset().top + $(this).height(); b = $(window).scrollTop() + $(window).height(); if (a < b) $(this).fadeTo(500,1) ???AND SLIDE CHILD ELEMENT ALSO!!???; ///how to I target each child element to do something in the above line??? }); }); 

这是一个jsFiddle DEMO ,它将帮助您可视化我的概念。 动画已经有效,问题是滑动的子元素最初开始,我想要做的是在每个onScroll渐变开始时连续开始每个滑动function。 非常感谢您提前做好准备。 这将帮助我在jQuery的路径和磨难中度过难关!

如果要在淡入淡出完成后执行某些操作,请创建一个在动画结束时触发的回调函数:

 var that = $(this); if (a < b) $(this).fadeTo(500,1, function() { alert ("Do something afterwards"); that.children().someAction(); }); 

我希望,这就是你想要的。

为了让您的示例正常工作,您可以使用:

 $(window).scroll(function(d,h) { tiles.each(function(i) { a = $(this).offset().top + $(this).height(); b = $(window).scrollTop() + $(window).height(); var that = $(this); if (a < b && true != $(this).data('faded')) { $(this).data('faded', true).fadeTo(500,1, function() { that.find('div').animate({left: '+=300', top: '+=12'}, 4500); }); } }); }); 

这是一个演示: http : //jsfiddle.net/mSRsA/