我有这样的东西,我需要在每个父母的主要div中显示每个名为“plink”的div,所以我试图淡化“.plink”,但它为所有div做同样的功能“ plink“
<script>
$(document).ready(function(){
$('.plink').hide();
$('.project').mouseover(function(){
$(this).next('.plink').fadeIn(400);
});
$('.project').mouseleave(function(){
$(this).next('.plink').fadeOut(200);
});
});
</script>
<div class="project">
<div class="plink">
<div class="go"></div>
<div class="goplus"><img src="images/more.png" border="0"/></div>
</div>
<div class="pic"><img src="images/portfolio_pic2.png" border="0" alt="projectname"/></div>
<div class="title">Test1</div>
</div>
<div class="spacer_project"></div>
<div class="project">
<div class="plink">
<div class="go"></div>
<div class="goplus"><img src="images/more.png" border="0"/></div>
</div>
<div class="pic"><img src="images/portfolio_pic.png" border="0" alt="projectname"/></div>
<div class="title">test2</div>
</div>
答案 0 :(得分:4)
您可以使用find()
代替next()
...
$(this).find('.plink').fadeIn(400);
因为this
是您的.project
div,所以您需要“找到”您要查找的子元素。使用next()
意味着如果它与选择器匹配,您将获得下一个元素(即检查下一个.project
div是否与.plink
选择器匹配)
答案 1 :(得分:0)
我会像musefan建议的那样走向FIND路线。这是解决方案代码:
<div class="project">
<div class="plink">
<div class="go">go</div>
<div class="goplus">goplus</div>
</div>
<div class="pic">pic</div>
<div class="title">Test1</div>
</div>
<div class="spacer_project"></div>
<div class="project">
<div class="plink">
<div class="go">go</div>
<div class="goplus">goplus</div>
</div>
<div class="pic">pic</div>
<div class="title">Test2</div>
</div>
$('.plink').hide();
$('.project').mouseover(function(){
$(this).find('.plink').fadeIn(400);
});
$('.project').mouseleave(function(){
$(this).find('.plink').fadeOut(200);
});
我用jsfiddle的简单文本替换了破碎的img链接。