[英]jQuery animate only when slider div active
here is the code: http://jsfiddle.net/duNHJ/2/这是代码: http://jsfiddle.net/duNHJ/2/
Basically there is an animations every div so when I click next or prev slider that animation script shoud run only when activated div.基本上每个 div 都有一个动画,所以当我单击 next 或 prev slider 时,animation 脚本应该仅在激活 div 时运行。 Currently it animates all of them at the beginning.
目前它在开始时为所有这些设置动画。
using http://www.malsup.com/jquery/cycle/使用http://www.malsup.com/jquery/cycle/
Also how can add active class on activated div?另外如何在激活的 div 上添加 active class?
I wasn't too sure what you wanted with regards to your first concern, however with regards to adding/remove an active state class, see the following example:关于您的第一个问题,我不太确定您想要什么,但是关于添加/删除活动的 state class,请参见以下示例:
Any script will simply be run as soon as it is loaded.任何脚本都会在加载后立即运行。 Also, with the selector
$('.test')
, the animation will be run on all elements with class test
.此外,使用选择器
$('.test')
, animation 将在所有带有 class test
的元素上运行。 You want to animate when the div changes.您想在 div 更改时设置动画。 The jQuery Cycle Plugin provides callback methods to do this:
jQuery Cycle Plugin 提供了回调方法来做到这一点:
$('#example').cycle({
fx: 'scrollLeft',
timeout: 5000,
before: onBefore,
after: onAfter
});
Where the function onBefore()
is called before the transition, and onAfter()
is called after.其中 function
onBefore()
在转换前调用, onAfter()
在转换后调用。 In your case, just use onAfter()
(and get rid of the inline scripts):在您的情况下,只需使用
onAfter()
(并摆脱内联脚本):
function onAfter() {
// $(this) references the current slide
$(this).animate({
top: "100px"
}, 1000);
}
$('#s6').before('<div id="nav">').cycle({
fx: 'fade',
timeout: 6000,
delay: -2000,
pager: '#nav',
next: '#next2',
prev: '#prev2',
activePagerClass: 'activeSlide',
after: onAfter
});
Demo: http://jsfiddle.net/jtbowden/cmwc3/演示: http://jsfiddle.net/jtbowden/cmwc3/
I am not sure exactly what animation you want to happen, but this should get you started.我不确定你想要发生什么 animation ,但这应该让你开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.