2014-10-29 89 views
1

我有四行文字,我想在每行的右侧显示mouseenter上的特定图像。jQuery show/hide/mouseenter问题

我有现在的问题是,所有的四个图像同时显示beeing。

我在做什么错?

http://jsfiddle.net/m97qebjr/10

的jQuery:

$(".thumb").hide(); 
$(".text").mouseenter(function() { 
$(".thumb").show(); 
}).mouseleave(function() { 
$(".thumb").hide(); 
}); 

回答

0

你不需要jQuery的根本:http://jsfiddle.net/m97qebjr/16/

.thumb { 
    display:none; /* added line */ 
    float:right; 
    overflow:hidden; 
    width:100px; 
    height:100px; 
} 
.wrap:hover .thumb{ /* added rule */ 
    display:block; 
} 
+0

纯CSS也很棒...非常感谢! – Too 2014-10-29 21:58:51

+0

@too欢迎您 – 2014-10-29 22:00:33

+0

这显示图像.wrap'悬停时',他的版本显示,只有当'.text'悬停图像。 – 2014-10-29 22:03:51

0

$(".thumb")匹配所有类拇指元素。试试这个:

$(".thumb").hide(); 
$(".text").mouseenter(function() { 
    $(this).siblings(".thumb").show(); 
}).mouseleave(function() { 
    $(this).siblings(".thumb").hide(); 
}); 

更新小提琴:http://jsfiddle.net/m97qebjr/13/

+0

非常感谢,这工作得很好! – Too 2014-10-29 21:57:00