首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spin.js -不能移除旋转器吗?

spin.js -不能移除旋转器吗?
EN

Stack Overflow用户
提问于 2014-05-24 15:57:55
回答 1查看 2.4K关注 0票数 3

不管我怎么试,我似乎都阻止不了这个旋转者。

我四处寻找方法去做,但没有做任何尝试。

小提琴:

http://jsfiddle.net/gmvT4/5/

备份代码:

代码语言:javascript
复制
var opts = {
    lines: 13, // The number of lines to draw
    length: 5, // The length of each line
    width: 2, // The line thickness
    radius: 5, // The radius of the inner circle
    corners: 1, // Corner roundness (0..1)
    rotate: 58, // The rotation offset
    direction: 1, // 1: clockwise, -1: counterclockwise
    color: '#fff', // #rgb or #rrggbb or array of colors
    speed: 0.9, // Rounds per second
    trail: 100, // 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
    left: '50%' // Left position relative to parent
};

var target = document.getElementById('foo');

$(document).on('click', '#spin', function () {
    var spinner = new Spinner(opts).spin(target);
});

$(document).on('click', '#stop', function () {
    $("#foo").data('spinner').stop();
});

<div id="foo"></div>
<button id="spin">Spin!</button>
<button id="stop">Stop!</button>

谢谢你的帮助!克雷格。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-24 16:01:52

Uncaught TypeError: Cannot read property 'stop' of undefined

这个错误告诉了你一些事情。您正在尝试在.stop()上运行$("#foo").data('spinner')。相反,使用由spinner创建的实例,您需要首先声明该单击事件范围之外的实例。

代码语言:javascript
复制
var spinner;

$(document).on('click','#spin',function(){
  spinner = new Spinner(opts).spin(target);
});

$(document).on('click','#stop',function(){
  spinner.stop();
});

更新小提琴 c/o勒内·罗斯

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23847001

复制
相关文章

相似问题

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