[英]spin.js jquery not working
I'm trying to use this: http://fgnass.github.io/spin.js/ and it works fine when I just use it via the js they specify. 我正在尝试使用它: http : //fgnass.github.io/spin.js/当我通过他们指定的js使用它时,它工作正常。 However, when I want to use the jquery plug in, it doesn't work.
但是,当我想使用jquery插件时,它不起作用。 Don't I only need to do
$('#elementID').spin()
and it should start a spinner on that element? 我不需要做
$('#elementID').spin()
它应该在该元素上启动一个微调器吗?
EDIT: 编辑:
In the jquery plugin it says this: 在jquery插件中它说:
$('#el').spin(); // Creates a default Spinner using the text color of #el.
This is what I want to use. 这就是我想要使用的。 The regular js way that people have answered below does work, but I don't know why this jquery way isn't working as they specify.
人们在下面回答的常规js方式确实有效,但我不知道为什么这种jquery方式不能正常工作。
/*
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);
You also need to include Spin.js 您还需要包含Spin.js
$('#foo').spin();
如果您不想在JQuery中安装函数,则只需使用查询元素即可。
new Spinner().spin($('#foo')[0]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.