On a site I recently worked on I wanted to have an animation before the next page loaded. What I wanted to happen was: user clicks a link, animation plays out, page is loaded normally. It is a nice little effect, but this is probably a trick you want to use sparingly…please…use it sparingly.
This uses the delay, and easing plugins for jquery. The below example includes the animation just as an example.
$('#link').click(function(){
// Get the url of the link
var toLoad = $(this).attr('href');
// Do some stuff
$(this).animate({
marginRight: '50px',
marginLeft: '-175px'
}, 300, 'easeOutSine').animate({
marginRight: '-38px',
marginLeft: '-120px'
}, 500, 'easeOutBounce');
// Stop doing stuff
// Wait 700ms before loading the url
$(this).delay(700, function(){
window.location = toLoad;
});
// Don't let the link do its natural thing
return false;
});
2 Comments
Leave a CommentPerfect. This was exactly what I needed for a project I’m working on. Thanks very much.
28th Apr 2009
Thanks for sharing, using it on a splash page for a client.
8th Jan 2010