javascript - 在另一个插件中调用 jQuery 插件会停止工作吗?

标签 javascript jquery jquery-plugins

我使用了 2 个 jQuery 插件,一个称为 Cycle,用于在鼠标悬停时循环浏览图像(当鼠标在电视之外时停止循环),另一个称为 Cursometer,用于跟踪鼠标速度。我想将这两个插件集成在一起,以便循环的速度取决于鼠标的速度。但是,当我将 Cycle API 调用的部分添加到 Cursometer 的速度属性中时,Cycle 函数停止工作。我对 JQuery 很陌生,这与范围界定或立即调用有什么关系吗?当我将 Cycle 插件部分代码包含在其他插件调用(Cursometer)中时,为什么它不能工作?

Cycle 如何工作的示例:http://jsfiddle.net/sealife24/rwmLf63r/2/

JSfiddle 在这里: http://jsfiddle.net/sealife24/wsvoyue5/

    $('.slideshow-block').cursometer({
        onUpdateSpeed: function(mouseSpeed) {
            // mouseSpeed is the current cursor speed
            var currSpeed = parseInt(mouseSpeed);
            $speedometer.text(mouseSpeed);

            /* cycle plugin begin */
            $('.slides').cycle({
                fx:     'none',
                speed:   100,   // want to pass currSpeed here, but it didn't work, even doesn't work with a number here
                timeout: 70

            }).cycle("pause");

            $('.slideshow-block').hover(function(){
                $(this).find('.slides').addClass('active').cycle('resume');
            }, function(){
                $(this).find('.slides').removeClass('active').cycle('pause');
            });
            /* cycle plugin end */

        }

        /* if move the cycle plugin part here, cycle will work, but there is no way I could dynamically get the mouseSpeed from the Cursometer plugin */

    });

最佳答案

看来我们无法为此插件动态设置速度或超时。我尝试过,这就是我能实现的目标。

JsFiddle

 var $speedometer = $('#speedometer');

$('.slideshow-block').cursometer({
    onUpdateSpeed: function(mouseSpeed) {
        var currSpeed = parseInt(mouseSpeed*100);
        $speedometer.text(currSpeed);
        var slide= $(this).find('.slides');
        var opts = slide.data("cycle.opts");
        opts.timeout = currSpeed==0?(0.1):currSpeed;
        slide.cycle("resume");
        /* cycle plugin begin */
               /* cycle plugin end */

    }
});
 $('.slides').cycle({
            fx:     'none',
           // speed:   100,   // want to pass currSpeed here, but it didn't work
            timeout: 70

        }).cycle("pause");;

        $('.slideshow-block').hover(function(){
            $(this).find('.slides').addClass('active').cycle('resume');
        }, function(){
            $(this).find('.slides').removeClass('active').cycle('pause');
        });

关于javascript - 在另一个插件中调用 jQuery 插件会停止工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25982873/

相关文章:

javascript - HTML 5 视频无法播放

jQuery 数据绑定(bind) - 现在流行的插件是什么?

javascript - 正则表达式相关的混淆

javascript - 适用于 MooTools 框架的 Google Closure Compiler 外部文件

javascript - 使用 knockout 在一页中进行多个自动刷新数据绑定(bind)

javascript - 使用 jquery 脚本的自定义函数配置选项

jquery-ui - 嵌套的 jQuery UI 选项卡后退按钮历史记录

javascript - AngularJS:使用 ng-show/hide 动态维护下拉列表的 3 种状态(进行中、成功、错误)?

javascript - 仅针对选定的数据属性?

javascript - 我如何按类别而不是全部收集 "load more"数据