If you want to achieve a specific behavior using jQuery and the mouse event hover()
, you can easily do so.
$("img").hover(function() { //select the image being hovered
$(this).css("opacity","0.5"); //set opacity for this image
}, function() {
$(this).css("opacity","1"); //reset opacity to default
});
Check out the demonstration: http://jsfiddle.net/mVWdQ/
Instead of targeting all images with the element selector, you can use a specific class for only the necessary images.
Another option is to utilize animate().
$("img").hover(function() {
$(this).animate({opacity:0.5},500);
}, function() {
$(this).animate({opacity:1},500);
});
Here's another demo for reference: http://jsfiddle.net/mVWdQ/1/