这是一个纯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