I have a client with an event planning site asking his pages to fade into one another. I have no idea how I can accomplish this. Any ideas? Is there anyway to do this withou
Page Transitions are supported natively with IE, using the META
tag.
See the Microsoft page about Filters and Transitions for more
For a browser agnostic approach (using Javascript), see this Stack Overflow question
Won't work in IE, but WebKit and FireFox are both on the boat with CSS transitions, and they run a lot more smoothly than any JavaScript.
http://www.w3.org/TR/css3-transitions/
This should work, without relying on Ajax (jQuery) :
$(function(){
/*
Add this code to every page.
We start by hiding the body, and then fading it in.
*/
$('body').hide().fadeIn('fast');
/*
Now we deal with all 'a' tags...
*/
$('a').click(function(){
/*
Get the url from this anchors href
*/
var link = $(this).attr('href');
/*
Fade out the whole page
*/
$('body').fadeOut('fast', function(){
/*
When that's done (on the 'callback') send the browser to the link.
*/
window.location.href = link;
});
return false;
});
});
Worth noting however is that if you're loading js at the bottom of the page (as we're often told to do), on a slow page load the page might be visible, then invisible, and then fade in again... Which would look very strange.
A solution would be to just hide the body in CSS, but you might, possibly, have visitors with JS turned off but CSS turned on, then they'll just have a blank page. Alternatively you could use a tiny amount of js at the top of the page (not relying on jQuery) to hide the body.
Lastly, however, why? I think if I visited your site these effects would begin to seriously annoy me pretty quickly. Why not just take the user to the page they asked for?
try this jQuery plugin. it's a tutorial on page transitions
This might be a little late, but to Fade a page In when it loads, and then fade out On-click I'd suggest using jQuery. I wrote this quick little script that will do the trick that your after. Have a look at it, and I will explain below.
The CSS
body { display:none; }
The JS
$(document).ready(function()
{
$( 'body' ).fadeIn("slow", 0.0);
$( 'body' ).fadeIn("slow", 0.1);
$( 'body' ).fadeIn("slow", 0.2);
$( 'body' ).fadeIn("slow", 0.3);
$( 'body' ).fadeIn("slow", 0.4);
$( 'body' ).fadeIn("slow", 0.5);
$( 'body' ).fadeIn("slow", 0.6);
$( 'body' ).fadeIn("slow", 0.7);
$( 'body' ).fadeIn("slow", 0.8);
$( 'body' ).fadeIn("slow", 0.9);
$( 'body' ).fadeIn("slow", 1.0);
$('a').click(function(){
$('body').fadeOut();
setTimeout("nav('"+this.href+"')",1000);
return false;
});
});
function nav(href){
location.href=href;
};
The CSS holds back the display of the body, which allows the JS to start the fade effect on-load of the page. The body fadeIn is set at intervals to allow a smoother fadeIn effect, giving the site time to load. I've set the fadeOut effect to trigger when any anchor link is clicked (you could change it whatever you wish to act as the fade out trigger). When the page fades out, it will most likly fade to a 'White' screen. To avoid this, set your HTML background color to any HEX to match the sites color.
That script right there is probably the best solution and quickest to impliment on any site. It's been tested on IE7-8, FF 3+ and Opera 9-10 and works like a charm. Enjoy!
What happens with pages that contain Flash/Video elements or other complex stuff? Will those fade properly?