Created
August 23, 2011 14:15
-
-
Save wesen/1165230 to your computer and use it in GitHub Desktop.
Creating an ajax spinner with spin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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