The problem with all the previous answers is that the hover image does not load the page, so when the browser calls it, it takes time to load, and all this does not look very good.
What I am doing is that I put the original image and the hover image in 1 element and first hide the hover image. Then, when hovering in, I display the hover image and hide the old one, and when I hover over, I do the opposite.
HTML:
<span id="bellLogo" onmouseover="hvr(this, 'in')" onmouseleave="hvr(this, 'out')"> <img src="stylesheets/images/bell.png" class=bell col="g"> <img src="stylesheets/images/bell_hover.png" class=bell style="display:none" col="b"> </span>
JavaScript / jQuery:
function hvr(dom, action) { if (action == 'in') { $(dom).find("[col=g]").css("display", "none"); $(dom).find("[col=b]").css("display", "inline-block"); } else { $(dom).find("[col=b]").css("display", "none"); $(dom).find("[col=g]").css("display", "inline-block"); } }
This is for me the easiest and most effective way to do this.
Y2H Nov 12 '15 at 9:00 2015-11-12 09:00
source share