Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript spin.js-Can';你不拆下旋转器吗?_Javascript_Jquery_Spin.js - Fatal编程技术网

Javascript spin.js-Can';你不拆下旋转器吗?

Javascript spin.js-Can';你不拆下旋转器吗?,javascript,jquery,spin.js,Javascript,Jquery,Spin.js,不管我怎么做,我似乎都无法阻止这个旋转器 我到处寻找做这件事的方法,但我试过的都不管用 小提琴: 备份代码: 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 corn

不管我怎么做,我似乎都无法阻止这个旋转器

我到处寻找做这件事的方法,但我试过的都不管用

小提琴:

备份代码:

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>
var选项={
lines:13,//要绘制的行数
长度:5,//每行的长度
宽度:2,//线条粗细
半径:5,//内圈的半径
拐角:1,//拐角圆度(0..1)
旋转:58,//旋转偏移量
方向:1,//1:顺时针,-1:逆时针
颜色:“#fff”、//#rgb或#rrggbb或颜色数组
速度:0.9,每秒//圈
轨迹:100,//余辉百分比
shadow:false,//是否渲染阴影
hwaccel:false,//是否使用硬件加速
className:'微调器',//要分配给微调器的CSS类
zIndex:2e9,//z索引(默认为2000000000)
顶部:“50%”,//相对于父级的顶部位置
左:“50%”//相对于父对象的左位置
};
var target=document.getElementById('foo');
$(文档).on('单击','旋转'),函数(){
var微调器=新微调器(opts)。微调(目标);
});
$(文档)。在('click','#stop',函数(){
$(“#foo”).data('spinner').stop();
});
快速旋转
停止

谢谢你的帮助!Craig.

未捕获类型错误:无法读取未定义的属性“stop”

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

var spinner;

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

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

c/o ReneéRoth

未捕获类型错误:无法读取未定义的属性“stop”
比我快几秒钟:)检查工作情况