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;
});
4 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
This is exactly what I need for a job I’m working on, but I can’t get it to work… instead of the next page loading after the animation finishes, I get a browser message saying the address is undefined. I’m a bit of a novice with scripts – can you help?
25th Feb 2010
Don’t worry – I’ve sorted it now.
Thanks for the share.
25th Feb 2010