利用背景圖片 + :hover 偽類,效能最佳、無閃爍:
<style>
#sidebar div a {
display: block; width: 77px; cursor: pointer;
}
#live_chat a { background: url("scroll/live_chat1.jpg"); height: 76px; }
#live_chat a:hover { background: url("scroll/live_chat2.jpg"); }
#customer_survey a { background: url("scroll/survey1.jpg"); height: 75px; }
#customer_survey a:hover { background: url("scroll/survey2.jpg"); }
#newsletter_sign a { background: url("scroll/newsletter_sign_bg.jpg"); height: 76px; }
#newsletter_sign a:hover { background: url("scroll/newsletter_sign_bg1.jpg"); }
#back_top a { background: url("scroll/back_top1.jpg"); height: 40px; }
#back_top a:hover { background: url("scroll/back_top2.jpg"); }
</style>
<div id="sidebar">
<div id="live_chat"><a href="#"></a></div>
<div id="customer_survey"><a href="#"></a></div>
<div id="newsletter_sign"><a href="#"></a></div>
<div id="back_top"><a href="#"></a></div>
</div>
<img> 標籤)
<img id="banner" src="img1.jpg" alt="Banner">
<script>
$('#banner').hover(
function(){ this.src = 'img2.jpg'; }, // mouseenter
function(){ this.src = 'img1.jpg'; } // mouseleave
);
</script>
function preloadImages(arr) {
var imgs = [];
for (var i=0; i
/* 將多張圖合併為一張 sprite.png */
.icon { display:inline-block; width:32px; height:32px; background:url(sprite.png) no-repeat; }
.icon-chat { background-position: 0 0; }
.icon-chat:hover { background-position: 0 -32px; }
:hover 或 Sprite。<img> + jQuery 切換 src。