這是一個純CSS效果,你並不需要JS爲結賬CSS :hover
<article id="posts">
<img class="search" src="http://lorempixel.com/400/200/food/1/" />
<img src="http://lorempixel.com/400/200/food/2/" />
<h2>Title 1</h2>
<p>lorem ipsum 1</p>
</article>
的CSS
#posts img:nth-of-type(2){display:none}
#posts:hover img.search{display:none}
#posts:hover img:nth-of-type(2){display:inline-block}
THE DEMO
或本
#posts img:nth-of-type(2){display:none}
#posts:hover img:nth-of-type(1){display:none}
#posts:hover img:nth-of-type(2){display:inline-block}
THE DEMO
或本
#posts img.search +img{display:none}
#posts:hover img.search{display:none}
#posts:hover img.search +img{display:inline-block}
THE DEMO
或添加類.hover
上課後,IMG .Search
<article id="posts">
<img class="search" src="http://lorempixel.com/400/200/food/1/" />
<img class="hover" src="http://lorempixel.com/400/200/food/2/" />
<h2>Title 1</h2>
<p>lorem ipsum 1</p>
</article>
的CSS
#posts img.hover{display:none}
#posts:hover img.search{display:none}
#posts:hover img.hover{display:inline-block}
或
#posts .hover{display:none}
#posts:hover .search{display:none}
#posts:hover .hover{display:inline-block}
THE DEMO
的simpliest方式是這樣的:
#posts:not(:hover) img.hover{display:none}
#posts:hover img.search{display:none}
THE DEMO
去你conbine它,你有這樣的事情:
#posts:not(:hover) img.hover,#posts:hover img.search{display:none}
或本:
#posts:not(:hover) .hover,#posts:hover .search{display:none}
THE DEMO
首先糾正這個類=「搜索src =「images/search.jpng」你的報價搞砸了。 .zoom在哪裏? – Huangism
var search ='' 另外,你的代碼中的類是.zoom你應用懸停? – andrew
謝謝我正在嘗試不同的圖標,然後我改變爲其他圖標,我忘了糾正。但問題是一樣的! – John23