我已经使用外部控件设置了 jcarousel。当我将鼠标悬停在“控件”列表中的链接上时,轮播会滚动到相应的图像。
到目前为止,一切正常,但是当我将鼠标悬停在不同的“控件”链接上时,它会卡在第一个链接上并等待滚动动画完成。
// SCROLL TO LINK
$('#controls a').on('mouseover',function() {
var opt = $('#controls a').index(this)+1;
carousel.scroll($.jcarousel.intval(opt));
});
我不确定,但我想我必须停止“鼠标悬停”上运行的滚动动画才能解决这个问题。
我尝试了这些行(不起作用):
carousel.stop(true);
和:
carousel.scroll.stop(true);
有人可以帮我解决这个问题吗?可能有一个简单的解决方案,但我对 jQuery 或一般编程没有经验。
最佳答案
遇到同样的问题。找到了非常简单的解决方案。 将其放入“jquery.jcarousel.js”
/**
* Stop animates the carousel, jump To End (animate Slide).
*
* @method animate
* @return undefined
*/
stopAnimate: function() {
this.list.stop(true,true,true);
},
在此之后
/**
* Animates the carousel to a certain position.
*
* @method animate
* @return undefined
* @param p {Number} Position to scroll to.
* @param a {Boolean} Flag indicating whether to perform animation.
*/
animate: function(p, a) {
-/-/-/-/(several strings)
},
我的//滚动到链接//看起来像(我有附加自动滚动)
$('#controls a').hover(function() {
var opt = $("#controls a").index(this) + 1;
carousel.scroll(opt);
carousel.stopAuto();//autoScroll Stop
}, function() {
carousel.stopAnimate(); //! here is located our function
carousel.startAuto();//autoScroll Start
});
也许有人觉得它有用!
关于jquery - 如何stop() jcarousel滚动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12722974/