using hoverIntent.js - need to affect style on a menu item
Hi all. I'm not great with JS, but am trying to wade through it. I'm using the tutorial offered
here to build a dropdown navigation mega menu :).
Here's my js code:
- <script type="text/javascript">
- $( document ).ready( function ()
- {
-
- //magazine menu
- //Set custom configurations for dropdown menu
- var config = {
- sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
- interval: 50, // number = milliseconds for onMouseOver polling interval
- over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
- timeout: 300, // number = milliseconds delay before onMouseOut
- out: megaHoverOut // function = onMouseOut callback (REQUIRED)
- };
- $("ul#main-nav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
- $("ul#main-nav li").hoverIntent(config); //Trigger Hover intent with custom configurations
- }
- );
- //hover for magazine dropdown
- //On Hover Over -> http://www.sohtanaka.com/web-design/mega-drop-downs-w-css-jquery/
- function megaHoverOver(){
- $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
- }
- //On Hover Out
- function megaHoverOut(){
- $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
- $(this).hide(); //after fading, hide it
- });
- }
- </script>
and my HTML code:
- <ul id="main-nav">
- <li><a href="/" id="home" class="current">home</a></li>
- <li><a href="#" id="magazine">magazine</a>
- <div class="sub">
- [blah] content goes here
- </div>
- </li>
- </ul>
it all works beautifully, except the fact that the nav item takes a :hover attribute that doesn't stay put while the user mouses over the mega menu. the css looks like this:
- ul#main-nav li a#magazine:hover{
- background-color:#a5abaf;
- color:black;
- }
I tried adding a css class to that menu object on the Hover Over function, but the mouse out event still turns the menu item back to its default color. Any ideas?
Thanks!