How to stop jcarousel immediately on mouseover and

2019-06-28 04:37发布

I'm trying to stop a transition with an action(in this case on hover), but i don't know how to achieve it. This is where i'm making the test:

http://lvemil.net/gla/web/

I have 3 instances of jcarousel and my goal is to stop the movement(immediately) on mouseover. The problem is: when the mouse is over the carousel, i stop it, but the current transition is ended before the stop, and the sensation is not the desired, i wish to stop the movement immediately on mouseover.

This is the initialization for the first carousel:

$('#jcarousel1')
.jcarousel({
    'animation': {
        'duration': 6000,    //DEFINE SPEED
        'easing':   'linear',
        'complete': function() {
        //ON ANIMATION COMPLETE ACTION GO HERE
        }
    },
    'wrap': 'circular'


}).jcarouselAutoscroll({
    interval: 1,
    target: '+=1',
    autostart: true
}).on('mouseover',function(e){
    $(this).jcarouselAutoscroll('stop');
}).on('mouseout',function(e){
    $(this).jcarouselAutoscroll('start');
});

The others two instances of jcarousel are similar initialized.

UPDATE: I already tried:

$('#jcarousel1').jcarousel('list').stop();

This stops the movement (scrolling) but i'm not able to start the movement again on mouse out in the same position it was before.

UPDATE 1: I also tried on mouseout (and make it work again)

$('#jcarousel1').jcarousel('destroy')
$('#jcarousel1').jcarousel( arrayWithInitOptions )

but this has an undesired effect because start the movement from the beginning of the carousel(a reload), from the first item, and i want to restart from the same position it was on mouseover.

1条回答
Bombasti
2楼-- · 2019-06-28 05:20

You may use something like this

    <script type="text/javascript" src="jquery.jcarousel.min.js"></script>
    <script type="text/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();
        });
    };

    jQ=jQuery.noConflict();
    jQ(document).ready(function() {
        jQ('#mycarousel').jcarousel({
                    auto: 3,
                    animation: 1000,
                    scroll: 1,
                    easing: "linear",
                    wrap: 'circular',
                    initCallback: mycarousel_initCallback
        });
    });

    </script>
查看更多
登录 后发表回答