按钮悬停时连续滚动jCarousel

时间:2011-11-15 21:46:58

标签: javascript jquery jcarousel

我正在使用jCarousel插件,我遇到了路障......

每当导航按钮悬停时,我都需要旋转木马连续滚动。将内置配置变量更改为“鼠标悬停”只需在每个悬停时滚动一次。

我遇到this similar question,但我不是javascript专家,无法得到解决方案。

这是我的代码:

    function mycarousel_initCallback(carousel)
{

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 10,
        start: 1,
        scroll: 1,
        animation: 'slow',
        wrap: 'circular',
        buttonNextEvent: 'mouseover',
        buttonPrevEvent: 'mouseover',
        initCallback: mycarousel_initCallback
    });
});

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

您可以使用以下脚本使其正常工作。我已在jquery.jcarousel.jsjquery-1.4.1

上对其进行了测试

要注意,我的jcarousel设置没有自动滚动。

<script>
jQuery(document).ready(function() {
    var _this = null;
    $('.jcarousel-next').mouseover(function() {
        if (!$(this).hasClass("jcarousel-next-disabled")) {
            _this = $(this);
            _this.click();
            window.setTimeout(CallAgain, 100);
        }
    });

    $('.jcarousel-next').mouseout(function() {
        if (!$(this).hasClass("jcarousel-next-disabled")) {
            _this = null;
        }
    });

    function CallAgain() {
        if (_this != null) {
            //alert("Inside Call again");
            _this.click();
            window.setTimeout(CallAgain, 100);
        }
    };

    $('.jcarousel-prev').mouseover(function() {
        if (!jQuery(this).hasClass("jcarousel-prev-disabled")){
            _this = $(this);
            _this.click();
            window.setTimeout(CallAgain, 100);
        }
    });

    $('.jcarousel-prev').mouseout(function() {
        if (!$(this).hasClass("jcarousel-next-disabled")) {
            _this = null;
        }
    });
});
</script>
相关问题