我想把velocity.js效果结合到Slick Carousel插件中。
slick:http://kenwheeler.github.io/slick/velocity:http://julian.com/research/velocity/
这很管用,但有一个奇怪的副作用:
<script>
$(function() {
$('.teaser').on('init', function(event, slick){
createSequence(0);
});
$('.teaser').on('beforeChange', function(event, slick, currentSlide, nextSlide){
createSequence(nextSlide);
});
$('.teaser').slick({
autoplay: true,
autoplaySpeed: 10000,
});
function createSequence(slideId) {
var $e = $('.slick-slide[data-slick-index='+slideId+']');
$e.velocity("stop");
var mySequence = [
{ e: $e.find('.teaserImg'), p: "transition.swoopIn", o: { duration: 500, sequenceQueue: false } },
{ e: $e.find('.boxTitle'), p: "transition.bounceUpIn", o: { duration: 500, sequenceQueue: false } },
{ e: $e.find('.projectTitle'), p: "transition.bounceLeftIn", o: { duration: 1000, sequenceQueue: false } },
{ e: $e.find('.teaserTitle'), p: "transition.bounceRightIn", o: { duration: 1000, sequenceQueue: false } },
{ e: $e.find('.teaserText'), p: "transition.fadeLeftBigIn", o: { duration: 500, sequenceQueue: false } },
{ e: $e.find('.teaserBtn'), p: "transition.fadeRightBigIn", o: { duration: 1000, sequenceQueue: false } }
];
$.Velocity.RunSequence(mySequence);
}
});
</script>
这是我现在得到的密码。所以我做了一个效果序列,它是用钩子beforeChange触发的。
当我转到下一张幻灯片时,它起作用了。但当我在幻灯片之间快速移动,一个序列还在播放时,所有的东西都变得乱七八糟,飞到屏幕上。
所以我要确保当前序列在执行下一个之前停止。这就是我不知道怎么做的地方。
有什么提示吗?
使用$e.velocity(“stop”,true);
清除动画队列并反转动画。
我所做的是在每个元素上添加一个css类(.animated
)来清除和重置动画。
function createSequence(slideId) {
var $e = $('.slick-slide[data-slick-index='+slideId+']');
$e.find('.animated').each(function (index, element) {
$(element).velocity('stop', true);
$(element).velocity('reverse', {duration: 1});
});
var mySequence = [
{ e: $e.find('.teaserImg'), p: "transition.swoopIn", o: { duration: 500, sequenceQueue: false } },
{ e: $e.find('.boxTitle'), p: "transition.bounceUpIn", o: { duration: 500, sequenceQueue: false } },
{ e: $e.find('.projectTitle'), p: "transition.bounceLeftIn", o: { duration: 1000, sequenceQueue: false } },
{ e: $e.find('.teaserTitle'), p: "transition.bounceRightIn", o: { duration: 1000, sequenceQueue: false } },
{ e: $e.find('.teaserText'), p: "transition.fadeLeftBigIn", o: { duration: 500, sequenceQueue: false } },
{ e: $e.find('.teaserBtn'), p: "transition.fadeRightBigIn", o: { duration: 1000, sequenceQueue: false } }
];
$.Velocity.RunSequence(mySequence);
}
来源:velocity.js stop命令