Непрерывно прокручивайте jCarousel при наведении курсора

Я использую плагин jCarousel и столкнулся с дорогой...

Мне нужно, чтобы карусель постоянно прокручивалась всякий раз, когда навигационные кнопки зависали. Изменение встроенных переменных конфигурации на "наведение мыши" просто прокручивает один раз за наведение.

Я сталкивался с подобным вопросом, но я не эксперт по 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 ответ

Вы можете использовать следующий скрипт, чтобы он работал. Я проверил это на jquery.jcarousel.js а также jquery-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>
Другие вопросы по тегам