首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从其他js文件中停止Spin.js

如何从其他js文件中停止Spin.js
EN

Stack Overflow用户
提问于 2014-04-23 16:12:45
回答 1查看 1.6K关注 0票数 0

我需要帮助

实际上,在我的工作中,我需要在jqgrid中实现spin.js和阻止UI。当我将代码放在同一个文件和函数中时,这是可以的,但是我想从其他JS文件中调用一个方法,并且听到的是我的问题所在。spin.js和块UI启动,然后取消块阻止UI停止,但spin.js仍在运行。

这是我的代码:

在jqgrid中的BeforeRequest()中,我调用了一个方法

代码语言:javascript
复制
 $.pui.common.loaderAnimationON("pane-content");

此方法具有以下代码

代码语言:javascript
复制
  loaderAnimationON: function (div) {
        var opts = {
            lines: 13, // The number of lines to draw
            length: 20, // The length of each line
            width: 10, // The line thickness
            radius: 30, // The radius of the inner circle
            corners: 1, // Corner roundness (0..1)
            rotate: 0, // The rotation offset
            direction: 1, // 1: clockwise, -1: counterclockwise
            color: '#000', // #rgb or #rrggbb or array of colors
            speed: 1, // Rounds per second
            trail: 60, // Afterglow percentage
            shadow: false, // Whether to render a shadow
            hwaccel: false, // Whether to use hardware acceleration
            className: 'spinner', // The CSS class to assign to the spinner
            zIndex: 2e9, // The z-index (defaults to 2000000000)
            top: '50%', // Top position relative to parent in px
            left: '50%' // Left position relative to parent in px
        };
        var target = document.getElementById(div);
        var spinner = new Spinner(opts).spin(target);


        $.blockUI({
            blockMsgClass: "gridProjectsLoader",
            message: null
        });

        return spinner;
    },

在gridComplete()中,我调用其他方法

代码语言:javascript
复制
     $.pui.common.loaderAnimationOFF("pane-content");

此方法具有以下代码

代码语言:javascript
复制
     loaderAnimationOFF: function (div) {
        var target = document.getElementById(div);
        var spinner = $.pui.common.loaderAnimationON();
        spinner.stop(target);
        $.unblockUI();
    }

有人能帮我吗?

谢谢各位

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-24 15:50:02

您应该使用同一个对象来启动和停止它。您可以在任何地方使用全局变量(只是另一个.js)检查这个jsFiddle。3秒后停止旋转。

http://jsfiddle.net/YX7dy/8/

代码语言:javascript
复制
spinner=loaderAnimationON('Spin');
setInterval(function(){spinner.stop();},3000);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23249901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档