Thumbnail opacity hover with CSS and jQuery

A nice effect when hovering over thumbnails is to change the opacity, so that it has that fade in and out effect.

<ul class="thumbnails">
 <li><a href="#"><img src="thumb-1.jpg" alt="" /></a></li>
 <li><a href="#"><img src="thumb-2.jpg" alt="" /></a></li>
 <li><a href="#"><img src="thumb-3.jpg" alt="" /></a></li>
 <li><a href="#"><img src="thumb-4.jpg" alt="" /></a></li>
 <li><a href="#"><img src="thumb-5.jpg" alt="" /></a></li>
</ul>

Take the above example, a simple list of images. Let’s apply the basic styling for it…

ul.thumbnails { list-style: none; margin: 0; padding: 0; }
ul.thumbnails li { float: left; margin: 10px; width: 50px; height: 50px; }
ul.thumbnails li img { filter: alpha(opacity=60); /* IE only */ opacity: .60; /* All other browsers */ }

As you can see all of the thumbnails will have a default opacity of 60%. Now comes the jQuery script to add the fade effect…

$(document).ready(function(){
 $('ul.thumbnails li').hover(function(){
  $('img', this).stop().animate({opacity: 1});
 }, function() {
  $('img', this).stop().animate({opacity: 0.6});
 });
});

And that’s all there is to it!

Pure CSS coke can spin

Pure CSS coke can spinThis just goes to show what you can do with CSS these days as Román Cortés demonstrates with his awesome spinning coke can example.

I found out that by a combination of the CSS1 properties background-attachment and background-position, 2D displacement maps could be created and, by scrolling, the displacement map would be applied to different parts of the texture (a background image).

With displacement maps lots of cool effects could be done, but thinking that the complexity of the displacement map would directly affect the CSS and markup size, choosing a good example took me some time. I thought in sea waves reflections, underwater distortions, magnifying glass, a rotating Earth… but the final thing I did was just right in my desktop: a Coke can – my favourite drink.

Due the cilindrical shape of a can, the displacement map is very simple with the parallel projection I did, so the code is very little – below 5kb – and easy to understand I hope.

Even if this effect is mainly CSS1 and some bits of CSS2 – for the scrolling div, overflow: auto property -, it is not going to work in IE6, because it doesn’t support background-attachment: fixed. I’ve tested it and it works in IE8, Firefox 3.5, Chrome 3, Safari 4 and Opera 10. Also, the code validates.

Check it out at http://www.romancortes.com/blog/pure-css-coke-can/