public
Last active

jQuery Plugin for Spin.js

  • Download Gist
jquery.spin.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/*
 
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);

Great work, thanks.

Very useful, thanks.I wrote small extension for simpler version https://gist.github.com/3180981

I forked and created this version of stop https://gist.github.com/4132376 I think it's cleaner to use the same function, e.g. target.spin(false);

How i use spin.js

1- div id="customSpinner" class="customSpinnercss" /div - [removing < ]

2- $('#customSpinner').spin();
3- .customSpinnercss {

color: black;
width: 150%;
height:1000px;
position: fixed;
left: auto;
top:auto;
bottom: auto;
right: auto;
z-index: 2147483646;
-moz-box-shadow: 0px 0px 3px #8a8a8a;
-webkit-box-shadow: 0px 0px 3px #8a8a8a;
box-shadow: 0px 0px 3px #8a8a8a;
background: transparent;
margin-left: -280px;
}
4- $('#customSpinner').data('spinner').stop();
Everything works fine. But after calling stop, do i need to alter z-index ? Because due to overlay div i cannot modify the content below that div. What i did is $(''#customSpinner').css('z-index','-1') after calling stop.

Any comments for this approach ?

I'd love to see this bundled into the spin.js project. :)

Thank you umairsaleemid. Your example worked perfectly.

Love this. I usually copy and paste the contents of spin.min.js into this file before using it, and remove the error handling for the Spinner object not being available.

Hey ITS-Florida: what's the license on this file?

Great work!

Sharing a live customizable fiddle for spin.js -http://bitconfig.com/spin/bitconfig_spin.html

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.