You can use CSS to change the background image of an element when you hover over it. The hover
pseudo-class is supported on most elements in recent browsers, but to be backwards compatible (Internet Explorer 6), you need to use an anchor tag for hover
to work.
The onclick event in the link is just so that nothing happens if you click it, it has nothing with the hovering effect to do. You can of course do something when the image is clicked, if you like.
HTML:
<a href="#" id="picture" onclick="return false;"></a>
CSS:
#picture {
display: block;
width: 200px;
height: 200px;
background-image: url(firstimage.gif);
border: none;
text-decoration: none;
}
#picture:hover {
background-image: url(hoverimage.gif);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…