我猜測這個關鍵字需要一行更改,但是我嘗試了一些不能按預期工作的東西。我試圖做的是我有圖像在網格中。一旦我將鼠標懸停在一張圖片上,它就需要展開。我可以得到這個效果,但是當我將鼠標移到一張圖片上時,所有圖片都在膨脹。我需要告訴我的jquery才能訪問鼠標懸停的圖片。如何只訪問被鼠標懸停的圖像
下面是代碼:
<script type="text/javascript">
$(function() {
var $container = $('#ib-container'),
$articles = $container.children('article'),
timeout;
var $img = $('img');
$articles.on('mouseenter', function(event) {
var $article = $(this);
clearTimeout(timeout);
$img.css({
height: '300px',
width: '620px'
timeout = setTimeout(function() {
if($article.hasClass('active')) return false;
$articles.not($article.removeClass('blur').addClass('active'))
.removeClass('active')
.addClass('blur');
}, 65);
});
$container.on('mouseleave', function(event) {
clearTimeout(timeout);
$articles.removeClass('active blur');
$img.css({ // resize the image
height: '165px',
width: '165px'
});
});
</script>
這裏是我的html:
<html>
<body>
<section class="ib-container" id="ib-container">
<article>
<header>
<h3><a target="_blank" href="Images/thumb/1_thumb.jpg"><img src="Images/main/1.jpg" width="165px" height="165px"><figcaption><em>Overview of Andaman</em></figcaption></figure></a></h3>
</header>
</article>
<article>
<header>
<h3><a target="_blank" href="Images/main/1.jpg"><img src="Images/main/1.jpg"><figcaption><em>Overview of Andaman</em></figcaption></figure></a></h3>
</header>
</article>
<article>
<header>
<h3><a target="_blank" href="Images/main/1.jpg"><img src="Images/main/1.jpg"><figcaption><em>Overview of Andaman</em></figcaption></figure></a></h3>
</header>
</article>
<article>
<header>
<h3><a target="_blank" href="Images/main/1.jpg"><img src="Images/main/1.jpg"><figcaption><em>Overview of Andaman</em></figcaption></figure></a></h3>
</header>
</article>
</section>
</body>
</html>
使用變量$ IMG = $( 'IMG')工作的代碼;在側面的mouseenter事件中,並寫下面的代碼 var $ img = $(this).find('img'); – 2015-02-06 05:58:22
檢查我把你的代碼放在jsfiddle上 http://jsfiddle.net/tsydav8n/1/ – 2015-02-06 06:04:24