0 Comments, 0 Tweets, why not add one?
So Sillyness newcomer Mark emailed me asking how to achieve the fading effect you see on the site. I thought that it was a good candidate for a tutorial, and even better, a great candidate for my new feature the Tuesday Howto.
So lets get this party started.
So when I was designing this version of Sillyness, I wanted to highlight the newest post in a way that was a bit subtler than some of my past attempts. Gone were borders and background colors; Right out were ginormous text treatments and flashing lights.
No, this time I wanted to err on the side of understatement and refinement. I started thinking about how spatially we distinguish nearer objects from farther ones. Obviously perspective is the main way in which we distinguish them, but another, very useful way is clarity.
Objects that are closer to you seem sharper, clearer and more in focus. As objects move away from you they lose definition and clarity, them dim if you will. This thought process brought me to a solution that I thought met all my requirements, and seemed like a fun challenge to boot.
So having decided on the effect I wanted, I need to figure out how to make it happen. Enter our friend jQuery.
I really can’t say enough good things about jQuery. It gets out of your way and makes complex things simple, and understandable. If you don’t use it, do your self a favor and go read the documentation. You will love Javascript when you are done, I guarantee it.
So in a nutshell, this is what the code I wrote does:
aged and shoves it into an array.old div to 1.0 and then fade it to 0.5 on mouseout.And that is all there is to it really. Here is the code that is running here on Sillyness:
$(document).ready(function() {
var num= 0.8;
var incr= 1;
var val= '';
$('.aged').each(function() {
$(this).fadeTo('fast', num - val);
val= '0.' + incr;
incr++;
});
$('.old').hover(
function() {$(this).children().fadeTo('fast', 1.0);},
function() {$(this).children().fadeTo('fast', 0.5);}
);
});
Hope you enjoy it, and please leave any questions/comments/improvements in the comments.
If you post about this on Twitter, please use the hashtag #silly867.