4

我已经设置了带有外部控件的 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 或一般编程没有经验。

4

3 回答 3

5

有同样的问题。找到了非常简单的解决方案。把它放在“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)
},

我的 //scroll to link// 看起来像(我有额外的 autoScrolling)

$('#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
    });

也许有人觉得它有用!

于 2012-12-10T03:34:37.380 回答
2

我有一个使用 jCarousel 控件的类似控件,当我将鼠标悬停在某些 div 上时,它会显示特定的图像。我还有一个问题,如果滚动动画已经在播放,轮播永远不会到达新目标。事实证明,停止当前播放动画所需的只是以下代码......

$(.jcarousel).jcarousel('list').finish();

我在指定新目标之前调用了它,它解决了我的问题。我希望这有帮助。

于 2014-01-17T19:57:51.200 回答
0

来自https://sorgalla.com/jcarousel/docs/plugins/autoscroll/reference/api.html

开始自动滚动:

$('.jcarousel').jcarouselAutoscroll('start');

停止自动滚动:

$('.jcarousel').jcarouselAutoscroll('stop');

我希望这有帮助。

于 2020-01-27T15:34:19.683 回答