简体   繁体   English

是否有可能使jQuery仅为悬停动画的目标div,如果它是正在悬停的元素的子元素?

[英]Is it possible to make jQuery only target div for hover animation if it is a child of the element being hovered over?

Okay, I am a beginner at Javascript and jQuery, so this may be a very simple question, but I've tried researching it, and can't quite find any good answers. 好的,我是Javascript和jQuery的初学者,所以这可能是一个非常简单的问题,但我已经尝试过研究它,并且找不到任何好的答案。

On my website: 在我的网站上:

http://joeyellisdesign.com/testingspace/JE2 http://joeyellisdesign.com/testingspace/JE2

I have a rollover on the "work" section of my portfolio that I am trying to make only appear when you hover over the individual image. 我在我的投资组合的“工作”部分进行了翻转,我试图只在您将鼠标悬停在单个图像上时显示。

To set up the animation, I have this code: 要设置动画,我有这个代码:

jQuery
$(document).ready(function(){
$(".project").hover(function(){
$(".projectdescription").animate({top:'4px'});
},function(){
$(".projectdescription").animate({top:'183.77px'});
});
});

Also, here is the CSS and HTML. 此外,这里是CSS和HTML。

<div class="project">
<a class="workanchor" href="#">
<img src="files/workthumbs/finsons.jpg">
<div class="projectdescription">
<h4>FINSON'S BEARD PRODUCTS</h4>
<p>Packaging and Identity</p>
<img class="plus" src="files/plus.png" width="129" height="129">
</div>
</a>
</div>


.project {
width: 295px;
height: 240px;
margin: 0px 1.25% 7%;
padding: 0px;
float: left;
overflow: hidden;
position: relative;
} 
#workcontainer .project .projectdescription {
background: #FFF;
margin: -4px 0px 0px;
padding: 0px;
width: 100%;
height: 240px;
position: absolute;
top: 183.77px;
} 
#work #workwrapper #workcontainer .project .workanchor .projectdescription .plus {
margin: 30px 0px 0px 83px;
padding: 0px;
height: 129px;
width: 129px;

} }

Thanks in advance for any and all help/and/or information that I know nothing. 提前感谢我所知道的任何和所有帮助/和/或信息。 ;) ;)

Try: 尝试:

$(".project").hover(function(){
    $(this).find(".projectdescription").animate({top:'4px'});
},function(){
    $(this).find(".projectdescription").animate({top:'183.77px'});
});
$(".project").on('mouseenter mouseleave', function(e){
     $(".projectdescription", this).animate({top: e.type=='mouseenter' ? '4px' : '183.77px'});
});

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM