Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

On my website:

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.

<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. ;)

like image 733
Joey Ellis Avatar asked Nov 27 '13 19:11

Joey Ellis


People also ask

What does the hover function in jQuery do?

The hover() method specifies two functions to run when the mouse pointer hovers over the selected elements. This method triggers both the mouseenter and mouseleave events. Note: If only one function is specified, it will be run for both the mouseenter and mouseleave events.

How do you know if an element is hovered?

Answer: Use the CSS :hover Pseudo-class You can simply use the CSS :hover pseudo-class selector in combination with the jQuery mousemove() to check whether the mouse is over an element or not in jQuery.


1 Answers

Try:

$(".project").hover(function(){
    $(this).find(".projectdescription").animate({top:'4px'});
},function(){
    $(this).find(".projectdescription").animate({top:'183.77px'});
});
like image 144
codingrose Avatar answered Oct 07 '22 16:10

codingrose