I've had some people asking: Oh great author, how did you do the cool and very awesome effect on the logotype at the top of this page?
Okay okay, I still only have two readers, both of them are friends and none of them cares, but here we go anyways.
In essence it's very simple, three images and about 60 lines of mootools powered code.
It starts with your basic logo, just as you'd expect on any page that has one of them, though it does help if it starts out as a transparent png. From this we cut out the parts we want to fade and animate. Any good old image-editing software can do this as long as it supports transparency. Note that the left and right margins on the corresponding cutout is left intact, this is to simplify positioning the overlays on top of the original image.
So to sum up, about now you are supposed to be sitting with something like this on your hard-drive:



Any questions? No? Good, just remember that the overlays need to have a transparent background or the fading in/out won't really work, even though you can still move them back and forth 'til your heart's content.
Go ahead and insert the logo in a div with your favourite text-editor and then we go over to the code.
I inject the overlays with javascript, mostly because I think it's annoying to have them on a page that doesn't support javascript to start with. Since we are using mootols. Go ahead and create the img divs and inject them into the div that you put the logo in. Remember that we saved the left and right margins in the images so that we can position them to the right and left by just using left:0 right:0. Over these I put an empty div to use for the mouse-enters event, I had some issues when it wasn't there but your mileage may wary.
To actually fade and animate the different elements we have created the mootools transition of your liking, personally I think that a second is a nice time but you are free to do whatever you feel like.
logo.set('morph',{duration:1000,transition:Fx.Transitions.Quad.easeOut});
logo_left.set('morph',{duration:1000,transition:Fx.Transitions.Quad.easeOut});
logo_right.set('morph',{duration:1000,transition:Fx.Transitions.Quad.easeOut});
logo_morph = logo.get('morph'); logo_left_morph = logo_left.get('morph'); logo_right_morph = logo_right.get('morph');
Now that we have the Morph objects available it's time to actually do something useful. Take the mouse-over element I mentioned previously and add mootools mouseenters and mouseleaves events to it.
mouse_over.addEvents({
mouseenter : function() {
logo_morph.cancel;
logo_left_morph.cancel();
logo_right_morph.cancel();
logo_morph.start({opacity:0}).chain(function(){
logo.setStyle('visibility', 'hidden');
});
logo_left.setStyle('visibility','visible');
logo_right.setStyle('visibility','visible');
if(logo.getStyle('visibility') != 'hidden'){
logo_left_morph.start({opacity:1}).chain(function(){
logo_left_morph.start({left:65});
});
logo_right_morph.start({opacity:1}).chain(function()
{logo_right_morph.start({right:66});
});
}
else{
logo_left_morph.start({left:65});
logo_right_morph.start({right:66});
}
},
});
A little more code to sink your teeth in. In essence it's actually really simple using Chains The Morph object will simple step through the chain on function after finishing the call to Morph.start(); So to break it down. On mouse over we start by canceling any ongoing Morph action and then starting with fading the logo out and the overlays out. Note that set visibility to hidden respectively visible on the elements faded, just to make sure that even if a browser doesn't play well with opacity it won't look horrible.
logo_morph.start({opacity:0}).chain(function(){
logo.setStyle('visibility', 'hidden');
});
logo_left.setStyle('visibility','visible');
logo_right.setStyle('visibility','visible');
That said and done we check if the logo image is visible or not, this is to prevent getting a delay of the animation while the hidden logo is faded out from 0 to 0 again since that's what we would have asked for.
if(logo.getStyle('visibility') != 'hidden'){
logo_left_morph.start({ opacity:1} ).chain(function(){
logo_left_morph.start({left:65});});
logo_right_morph.start({opacity:1}).chain(function(){
logo_right_morph.start({right:66});
});
}
So chain opacity->movement on the images and presto the effect is more or less complete. The other way around should be quite self-explanatory (if you managed to follow so far. If you didn't, don't fret – I'm horrible at explaining what the hell I'm doing), mouseleaves is just the same thing, but backwards.
That about it for today. If you want to play around with the code, it's not pretty nor is it properly objectified then take a gander over here Feel free to do whatever you want with it as long as you don't blame if it doesn't work or if it breaks anything