Skip to content

Instantly share code, notes, and snippets.

@wesen
Created August 23, 2011 14:15
Show Gist options
  • Save wesen/1165230 to your computer and use it in GitHub Desktop.
Save wesen/1165230 to your computer and use it in GitHub Desktop.
Creating an ajax spinner with spin.js
var spinnerOpts = {
lines: 10,
length: 7,
width: 3,
radius: 3,
trail: 40,
speed: 1.0
};
$.fn.spin = function(opts) {
this.each(function() {
var $this = $(this),
spinner = $this.data('spinner');
if (spinner) spinner.stop();
if (opts !== false) {
opts = $.extend({color: $this.css('color')}, opts);
spinner = new Spinner(opts).spin(this);
$this.data('spinner', spinner);
}
});
return this;
};
/* add ajax spinner */
$("body").ajaxStart(function () {
var elt = $('<div id="spinner"></div>');
elt.css({top: '15px',
left: '-30px',
position: 'relative'});
elt.spin(spinnerOpts);
$("#top .contents").prepend(elt);
})
.ajaxStop(function () {
$("#spinner").remove();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment