只有當圖像不重疊時才起作用(參見圖)。在你的情況下,所有的圖像具有完全相同的尺寸並且彼此堆疊。由於瀏覽器將圖像視爲固體對象(它們不會影響透明度),因此無法確定您想要在此刻懸停的圖像?
+-----------+-----------+
| | |
| img1 | img2 |
| | |
| | |
+-----------+-----------+
| | |
| img3 | img4 |
| | |
| | |
+-----------+-----------+
但是,您可以解決此問題:
只需使用一個單一的圖像映射在包含所有區域的圖像之一,並與一些JavaScript可以觸發所有其他懸停效果圖片。根據你的代碼
$("area").hover(function(){
var $target = $("#"+$(this).data("target")); // getting the target image
$target.attr("src",$target.attr("src").replace("slice","slice-focus")); //replacing the src with the src of the hover image
},function(){
var $target = $("#"+$(this).data("target"));
$target.attr("src",$target.attr("src").replace("focus-","")); //revert the changes
});
工作例如:jsFiddle-Demo
是否有一個重疊多個圖像的特殊原因?爲什麼不分離並將其全部顯示在一個圖層中? –
你可以問一個問題嗎? – Christoph
我添加了一個問題。無法使用一張圖片,因爲我想更改懸停時的單個圖片。 – Mark