Created
March 11, 2012 19:44
-
-
Save andrewjamesford/2017813 to your computer and use it in GitHub Desktop.
Code to invoke AJAX spinner using 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 spinner; | |
function FireSpinner() { | |
var opts = { | |
lines: 12, // The number of lines to draw | |
length: 12, // The length of each line | |
width: 7, // The line thickness | |
radius: 23, // The radius of the inner circle | |
color: '#fff', // #rgb or #rrggbb | |
speed: 1, // Rounds per second | |
trail: 60, // Afterglow percentage | |
shadow: true, // Whether to render a shadow | |
hwaccel: false // Whether to use hardware acceleration | |
}, | |
target = document.getElementById('loading'); | |
$('#loading').fadeIn(); | |
spinner = new Spinner(opts).spin(target); | |
} | |
// Ajax loader calls spinner | |
$('body').ajaxStop(function() { | |
$('#loading').fadeOut(); | |
spinner.stop(); | |
}).ajaxError(function(e, jqxhr, settings, exception) { | |
console.log('An error occurer with the last ajax request. Exception:' + exception); | |
$('#loading').fadeOut(); | |
spinner.stop(); | |
}); |
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
#loading { | |
position: absolute; | |
top:0; | |
left:0; | |
right:0; | |
bottom:0; | |
z-index:10000; | |
width:100%; | |
height:100%; | |
display: none; | |
background: -moz-radial-gradient(center, ellipse cover, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0) 100%); /* FF3.6+ */ | |
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(0,0,0,0.75)), color-stop(100%,rgba(0,0,0,0))); /* Chrome,Safari4+ */ | |
background: -webkit-radial-gradient(center, ellipse cover, rgba(0,0,0,0.75) 0%,rgba(0,0,0,0) 100%); /* Chrome10+,Safari5.1+ */ | |
background: -o-radial-gradient(center, ellipse cover, rgba(0,0,0,0.75) 0%,rgba(0,0,0,0) 100%); /* Opera 12+ */ | |
background: -ms-radial-gradient(center, ellipse cover, rgba(0,0,0,0.75) 0%,rgba(0,0,0,0) 100%); /* IE10+ */ | |
background: radial-gradient(center, ellipse cover, rgba(0,0,0,0.75) 0%,rgba(0,0,0,0) 100%); /* W3C */ | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a6000000', endColorstr='#00000000',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Grab spin.js from here: http://fgnass.github.com/spin.js/
You will require a div called loading just before the closing body tag of your HTML.