停止Spinner.js

Con*_*nor 6 javascript jquery

我正在使用spin.js(http://fgnass.github.com/spin.js/),同时加载一个大的全宽/高图像.问题是我在阻止旋转器方面遇到了麻烦.stop()方法似乎不起作用.这就是我所拥有的:

$(document).ready(function($) {
    var img = new Image();
    img.src = $('#top-bg').css('background-image').replace(/url\(|\)/g, '');

    img.onload = function(){
        $("#top-bg").spinner.stop();
        $(".top-bar").delay(1500).fadeIn(5000);
        $("#arrow, #arrowrt, #top-icons").delay(5000).fadeIn(5000);
    };
});
Run Code Online (Sandbox Code Playgroud)

我也试过了

.spin(false)
Run Code Online (Sandbox Code Playgroud)

.data('spinner').stop()
Run Code Online (Sandbox Code Playgroud)

这是微调器设置:

$(document).ready(function($) {
    var opts = {
    lines: 9, // The number of lines to draw
    length: 11, // The length of each line
    width: 4, // The line thickness
    radius: 10, // The radius of the inner circle
    rotate: 0, // The rotation offset
    color: '#fff', // #rgb or #rrggbb
    speed: 0.9, // Rounds per second
    trail: 54, // 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: 'auto', // Top position relative to parent in px
    left: 'auto' // Left position relative to parent in px
   };
   var target = document.getElementById('top-bg');
   var spinner = new Spinner(opts).spin(target);
});
Run Code Online (Sandbox Code Playgroud)

Nik*_*iko 19

您需要将微调器实例存储在某处 - 以便在需要它时可以访问它以停止旋转:

var spinner = new Spinner(opts).spin(target);
$(target).data('spinner', spinner);
Run Code Online (Sandbox Code Playgroud)

现在你可以像这样停下来:

$('#top-bg').data('spinner').stop();
Run Code Online (Sandbox Code Playgroud)


Vla*_*mir 6

您可以在没有实例的情况下停止微调

$(target).spin(false);
Run Code Online (Sandbox Code Playgroud)


Jam*_*mes 6

这似乎适用于浏览器并使用较少的代码:

$(".spinner").remove();
Run Code Online (Sandbox Code Playgroud)