下載圖像,直到CSS樣式被觸發不會發生通話。
有幾個方法可以做到這一點,並組織HTML你喜歡什麼,
- here is a crude example using your code顯示的原則。
MARKUP
<div class="preload1"></div>
<div class="preload2"></div>
<a href="http://officialacescottie.co.uk/Home/Home.html">click me</a>
* CSS *
a {
display: block;
width: 600px;
height: 114px;
background-image:url("/Buttons/Home.gif");
text-indent: -9999px;
outline: 0;
}
a:hover, .preload1 {
background-image:url("/Buttons/HomeP.gif");
}
a:active, .preload2 {
background-image:url("/Buttons/HomeC.gif");
}
/* hide these off page in a way that
the browser will still call the background-image */
.preload2, .preload1 {
position:absolute; left:-9999px; top:-9999px;
}
/* image urls are shortened here only so it presents better on SO */
這顯示了基本原則,即,當a:hover
被觸發時,所引用的背景圖像已經有有機會「預加載」到瀏覽器緩存。
非常感謝你。你的例子完美地工作。 – user3310078
@ user3310078好東西。不客氣,謝謝 –