CyberJunkie CyberJunkie - 10 days ago 6
CSS Question

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?

Answer

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/