javascript – spin.js jquery无效

前端之家收集整理的这篇文章主要介绍了javascript – spin.js jquery无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用它: http://fgnass.github.io/spin.js/并且当我通过它们指定的js使用它时它工作正常.但是,当我想使用jquery插件时,它不起作用.我不需要做$(‘#elementID’).spin()它应该在该元素上启动一个微调器吗?

编辑:

在jquery插件中它说:

$( ‘#报’)旋转(); //使用#el的文本颜色创建默认的Spinner.

这就是我想要使用的.人们在下面回答的常规js方式确实有效,但我不知道为什么这种jquery方式不能正常工作.

解决方法

fiddle Demo

jQuery Plugin

/*
You can now create a spinner using any of the variants below:

$("#el").spin(); // Produces default Spinner using the text color of #el.
$("#el").spin("small"); // Produces a 'small' Spinner using the text color of #el.
$("#el").spin("large","white"); // Produces a 'large' Spinner in white (or any valid CSS color).
$("#el").spin({ ... }); // Produces a Spinner using your custom settings.

$("#el").spin(false); // Kills the spinner.

*/
(function ($) {
    $.fn.spin = function (opts,color) {
        var presets = {
            "tiny": {
                lines: 8,length: 2,width: 2,radius: 3
            },"small": {
                lines: 8,length: 4,width: 3,radius: 5
            },"large": {
                lines: 10,length: 8,width: 4,radius: 8
            }
        };
        if (Spinner) {
            return this.each(function () {
                var $this = $(this),data = $this.data();

                if (data.spinner) {
                    data.spinner.stop();
                    delete data.spinner;
                }
                if (opts !== false) {
                    if (typeof opts === "string") {
                        if (opts in presets) {
                            opts = presets[opts];
                        } else {
                            opts = {};
                        }
                        if (color) {
                            opts.color = color;
                        }
                    }
                    data.spinner = new Spinner($.extend({
                        color: $this.css('color')
                    },opts)).spin(this);
                }
            });
        } else {
            throw "Spinner class not available.";
        }
    };
})(jQuery);

您还需要包括Spin.js

$('#foo').spin();

猜你在找的jQuery相关文章