好吧,我几乎实现了我的目标。有一个图像,当悬停时,一个 div 会随着文本和背景消失。问题是当用户悬停“新” div(文本和背景)时。
这是HTML:
<div id="wrap">
<div class="admin">
<div class="admin-img">
<img src="http://lorempixum.com/g/210/210/abstract" />
</div>
<div class="admin-txt">
<h2>Name</h2>
<p>Job description</p>
</div>
</div>
<div class="admin">
<div class="admin-img">
<img src="http://lorempixum.com/g/210/210/nature" />
</div>
<div class="admin-txt">
<h2>Name</h2>
<p>Job description</p>
</div>
</div>
<div class="admin">
<div class="admin-img">
<img src="http://lorempixum.com/g/210/210/sports" />
</div>
<div class="admin-txt">
<h2>Name</h2>
<p>Job description</p>
</div>
</div>
<div class="other">
<div class="other-img">
<img src="http://lorempixum.com/g/100/100/city" />
</div>
<div class="other-txt">
<h3>Name</h3>
<p>Job description</p>
</div>
</div>
<div class="other">
<div class="other-img">
<img src="http://lorempixum.com/g/100/100/nightlife" />
</div>
<div class="other-txt">
<h3>Name</h3>
<p>Job description</p>
</div>
</div>
<div class="other">
<div class="other-img">
<img src="http://lorempixum.com/g/100/100/people" />
</div>
<div class="other-txt">
<h3>Name</h3>
<p>Job description</p>
</div>
</div>
<div class="other">
<div class="other-img">
<img src="http://lorempixum.com/g/100/100/food" />
</div>
<div class="other-txt">
<h3>Name</h3>
<p>Job description</p>
</div>
</div>
<div class="other">
<div class="other-img">
<img src="http://lorempixum.com/g/100/100/animals" />
</div>
<div class="other-txt">
<h3>Name</h3>
<p>Job description</p>
</div>
</div>
</div>
这是我使用的 jQuery:
$(document).ready(function() {
$("div.admin-img").hover(
function () {
$(this).siblings('.admin-txt').stop(true,true).fadeIn(100);
},
function () {
$(this).siblings('.admin-txt').stop(true,true).fadeOut(100);
});
$("div.other-img").hover(
function () {
$(this).siblings('.other-txt').stop(true,true).fadeIn(100);
},
function () {
$(this).siblings('.other-txt').stop(true,true).fadeOut(100);
});
});
我怎样才能让它变得更好?而且,在小图像上,如何使背景覆盖整个图像?
在此先感谢,丹妮。