performance - jQuery addClass/Mouse-over timeout combo issue -
The block of code below works perfectly until I add the mouse over the timeout. The mouse works longer than the mouse but the classes are no longer connected. Is there a way to combine both and still classes are considered?
$ (document) .ready (function () {var myTimeout; $ ('# nav-bar & gt; ul Li'). Myth (work () {myTimeout = setTimeout (function ($ ('. Drop-down-plates: visible') Hide (); $ ('# nav-bar ul li.current-menu- (' current-menu-item '); $ (' # navy Eq ($ (this). Index ()). AddClass ('current -menmen-item'); $ ('drop-down-plates'). Eq ($ (this) .index ( $ ('# Nav-bar ul li.current-dmenu-item'). RemoveClass ('current muclove (function () () {explicit timeout (my timeout);}); $ (' # Drop-down-box '). MUSELEVE (function () {$ (' .drop-down-p ('Current- dmenu-item');});});
Within the timeout, this
element will not contain you. Caching the reference can be done in a variable outside.
$ (document) .ready (function () {var myTimeout, $ ('# nav-bar & gt; Ul Li '). Save the reference to the mouseenter (function () {$ this = $ (this); // element myTimeout = setTimeout (function () {$ ('. Drop-down-plates: visible'). Hide (); $ (' RemoveClass ('Current Menu Item'); $ ('# nav-bar ul li'). Eq ($ this.index ()) .addClass ('Current - $ ('drop-down-plates'). Eq ($ this.index ()). SlideDown ($); $ ('# nav-bar ul li.current $ (' # drop- Drop-box '); RemoveClass (' current-denom-object ');}, 200);}) .moveleave (function () {clear timeout (myTimeout);}) .mouseleave (function () {$ (' Drop-down-plates: visual '). Slideshow (); $ ('# Nav-bar ul li.current-dmenu-item'). RemoveClass ('current-dmenu -item');});});
In this case you can also save the pointer of the hovered element outside the hovered element as you are using it to find only the pointer.
Comments
Post a Comment