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

Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointscreating a sliding event on a menu using jquery
l have created a menu that currently has a dropdown down. the dropdown got the code below but what i would want to be able to do is that l want to make the dropdown slide down. so l tried using slideup and down but it doesnt seem to work. the code is below. any ideas how l can make it to perfection? Andrew Chalkley
$(document).ready(function() {
$('.myMenu > li').bind('mouseover', openSubMenu);
$('.myMenu > li').bind('mouseout', closeSubMenu);
function openSubMenu() {
$(this).find('ul').css("visibility", "visible").slideDown();
};
function closeSubMenu() {
$(this).find('ul').css("visibility", "hidden").slideUp();
};
});

Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsthat dont seem to work mate

Matt Brock
28,330 PointsWhat are your initial visibility settings for .myMenu in your CSS? I would set your .myMenu display setting to css display: none;
and remove the javascript .css("visibility", "visible")
part of your function.
.myMenu {
display: none;
}
$(document).ready(function() {
$('.myMenu > li').bind('mouseover', function() {
$(this).slideDown();
});
$('.myMenu > li').bind('mouseout', function() {
$(this).slideUp();
});
});
2 Answers

Zoltán Holik
3,401 Points<ul class="myMenu">
<li>Menu item
<ul>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
</ul>
</li>
<li>Menu item
<ul>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
</ul>
</li>
<li>Menu item</li>
<li>Menu item</li>
<li>Menu item</li>
</ul>
.myMenu li ul{
display: none;
}
Quick tip to prevent Animation queue Buildup :) Need to use the stop() function.
$(document).ready(function() {
$('.myMenu li').on('mouseover', function(){
$(this).find('ul').stop().slideDown();
}).on('mouseout', function(){
$(this).find('ul').stop().slideUp();
});
});

Matt Brock
28,330 PointsNice!

Zoltán Holik
3,401 PointsThanks! :) And another quick tip is to use on() method instead of bind(). Here is an article about why: http://www.elijahmanor.com/differences-between-jquery-bind-vs-live-vs-delegate-vs-on/

Wilson Muñoz
16,913 PointsTry using .mouseover() with a callback $( "#outer" ).mouseover(function() { $( "#log" ).append( "<div>Handler for .mouseover() called.</div>" ); });
In your case you may try:
$('.myMenu > li').mouseover(function(){
alert("Heyo!"); $(this).slideToggle(); });
Matt Brock
28,330 PointsMatt Brock
28,330 PointsTry inserting the respective functions inside the .bind() method call. Also, the .find() method only locates descendants, so you could just leave it out and use $(this) to apply the .slideDown() and .slideUp() methods directly to the $('.myMenu > li') elements:
I think this will work, but if not, the .bind() method docs are helpful. Let me know how it goes!