Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Stop animation trigger

Hey guys I am creating a small site with some of the ideas and skills learned from Treehouse! But I am having an issue with fixing an .animation idea with Jquery.

<script>
        $("#nav-line").mouseenter(function() {
           $("#nav-line").animate({
            height: "4.7em"
           });
        $("#click").animate ({
                fontSize: "4em"
           });
        $("#nav-ul").fadeIn("slow");
        });
    </script> 

Here is the code for the animation, once the mouse exits the "#nav-line" all of the above code will be set back, BUT the nav links are under the "#nav-line" so when the animation is set back, it trigger immediately after.

I have tried .delay but that only......delays the animation. Anyone know how this can be overcome? maybe adding an if statement or something!

Thank you

2 Answers

Eduardo Garcia
Eduardo Garcia
4,571 Points

Add .mouseleave to reset the #nav-line after the mouse leaves. If you use .mouseout, moving the mouse into child elements will be considered "leaving" #nav-line which may not have the desired effect.

$("#nav-line").mouseleave(function() {
           $("#nav-line").animate({
            height: "original text size"
           });

OK thank you I will give that a try