【问题标题】:jQuery cycle on "hover" start from image "0" again“悬停”上的jQuery循环再次从图像“0”开始
【发布时间】:2016-11-16 13:11:31
【问题描述】:

我有一个简单的问题。 基于这个 fiddle with jquery 循环插件:
http://jsfiddle.net/Kz6Gk/353/

我希望滑块在鼠标移出时重置,所以下次我再次将鼠标悬停在它上面时,它将从第一张图像开始。

我尝试了许多选项,例如destroyreinitgotostartingslide,但我无法使其工作,它总是从最后一次调用 mouseout 之前的最后一个滑块恢复。
例如,我像这样修改了代码的最后一部分,它应该可以工作但还没有运气:

jQuery(function($){
    // Cycle plugin
    $('.slides').cycle({
        fx: 'none',
        speed: 1,
        timeout: 770
    }).cycle("pause");
    // Pause & play on hover
    $('.slideshow-block').hover(function(){
        $(this).find('.slides').addClass('active').cycle('resume');
    }, function(){
        $(this).find('.slides').removeClass('active').cycle('goto', 0).cycle('pause');
    });

});

【问题讨论】:

    标签: jquery cycle


    【解决方案1】:

    参考fiddle JS:

    $(function($){
    
        // Cycle plugin
    function recycle()
    {
    $('.slides').cycle("destroy").cycle({
        fx:  'none',
        speed: 1,
        timeout: 700
    });
    }
        // Pause & play on hover
        $('.slideshow-block').hover(function(){
        recycle();
            $(this).find('.slides').addClass('active').cycle('resume');
        }, function(){
        recycle();
            $(this).find('.slides').removeClass('active').cycle('pause');
        });
    
    });
    

    【讨论】:

    • 谢谢两位,还有一些小问题,我在这里问或者我投反对票没关系?
    【解决方案2】:

    你可以通过再次调用cycle(option)来重新初始化循环

    jQuery(function($){
    
    var initCycle = function(){
    // Cycle plugin
    $('.slides').cycle({
        fx:     'none',
        speed:   1,
        timeout: 770
    }).cycle("pause");
    }
    
    // Pause & play on hover
    $('.slideshow-block').hover(function(){
        $(this).find('.slides').addClass('active').cycle('resume');
    }, 
    //re initiate after lost hover
    initCycle });
    
    //initiate cycle after page load
    initCycle();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      相关资源
      最近更新 更多