简体   繁体   中英

jQuery dropdown menu CSS manipulation

I'm using the jQuery Simple Drop-Down Menu Plugin from http://javascript-array.com/scripts/jquery_simple_drop_down_menu/

In their example, when you hover a menu item, a red dropdown box appears. I can't figure out how to make the main tab red as well while the dropdown is visible. It should remain red when you also hover on the dropdown and return to normal via timeout. The code uses a timeout function so I'll have to somehow implement it into that.

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

I tried making a function for changing the background CSS and adding it to mouseover and mouseout, but it either changes the background for all menu tabs or nothing happens. Does anyone know a good solution?

Just add these lines to css

#jsddm li a:hover
{   
background: #8EA344
}

put any color in the background you want.

Update your style sheet with this:

#jsddm li a:hover
    { background: #24313C }

    #jsddm li:hover > a
    { background: #24313C; display:block }

See the Demo:

http://jsfiddle.net/rathoreahsan/evcL2/2/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM