I have a JavaScript/jQuery function that handles the drop down menu's for several different sites. I am a new to JavaScript and jQuery and would love any input on how to clean up my code. Essentially, I am asking how to make this script more efficient and less clunky, so I can improve performance and write better code.
Thanks.
html:
<!doctype html>
<html>
<head>
<title> </title>
<!--stylesheets-->
<link rel="stylesheet" href="../css/reset.css">
<link rel="stylesheet" href="../css/master.css">
<!--custom fonts-->
<!--JS-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"> </script>
<script src="functions.js"></script>
<script>
$(function() {
dropdownSlide('.ppt-menu', 'ul.sub-menu', 5000, fade)
})
</script>
</head>
<body>
<nav id="test-menu" class="ppt-menu">
<ul id="menu-main-nav-1" class="menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-63"> <a href="http://blakecommunications.com/">Home</a></li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-65"><a href="http://blakecommunications.com/about">About</a>
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-60"><a href="http://blakecommunications.com/about/approach/">Approach</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-62"><a href="http://blakecommunications.com/about/industries/">Industries</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-91"><a href="http://blakecommunications.com/about/services/">Services</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-61"><a href="http://blakecommunications.com/about/stephanie-blake-bio/">Bio</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-120"><a href="http://blakecommunications.com/projects">Projects</a>
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-93"><a href="http://blakecommunications.com/projects/uccs/">UCCS</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-92"><a href="http://blakecommunications.com/projects/the-dixon-collective/">The Dixon Collective</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-120"><a href="http://blakecommunications.com/projects">Projectsttow</a>
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-93"><a href="http://blakecommunications.com/projects/uccs/">UCCS</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-92"><a href="http://blakecommunications.com/projects/the-dixon-collective/">The Dixon Collective</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-57"><a href="http://blakecommunications.com/contact/">Contact</a></li>
function dropdownMenu(nav, dropdown, speed, type) {
var nav = $(nav), dropdown = $(dropdown);
var parentItem = $(nav).find('li').has(dropdown);
$(parentItem).find(dropdown).hide();
if( type === slide ) {
$(parentItem).mouseenter(function () {
$('li').find(dropdown).hide();
$(this).find(dropdown).stop(true, true).slideDown(speed);
}).mouseleave(function () {
$(this).find(dropdown).delay(500).slideUp(speed);
});
}
else if ( type === fade ) {
$(parentItem).mouseenter(function () {
$('li').find(dropdown).hide();
$(this).find(dropdown).stop(true, true).fadeIn(speed);
}).mouseleave(function () {
$(this).find(dropdown).delay(500).fadeOut(speed);
});
}
else if( type === show) {
$(parentItem).mouseenter(function () {
$('li').find(dropdown).hide();
$(this).find(dropdown).stop(true, true).show(speed);
}).mouseleave(function () {
$(this).find(dropdown).delay(500).hide(speed);
});
}
else {
$(parentItem).mouseenter(function () {
$('li').find(dropdown).hide();
$(this).find(dropdown).stop(true, true).show();
}).mouseleave(function () {
$(this).find(dropdown).delay(500).hide();
});
}
}