SHORT ANSWER: hoverIntent will not work onMouseOver/onMouseOut. The children would be firing events, starting and stopping timers, resetting mouse coordinates, etc. It would be a mess. The reason hoverIntent works (well, almost works... there are still some bugs) is that it tracks mouse movement over a larger area (regardless of nested children).
LONG ANSWER: I chose to mimic jQuery's hover function because it implements a cross-browser type of IE's onMouseEnter / onMouseLeave. Without that, onMouseOver and onMouseOut will fire your functions on every child, grandchild, etc. If you attached onMouseOver and onMouseOut to the <ul> both events would fire when you mouse over every LI, A, and SPAN inside that UL... and you'd have to cancel the effects of each and perform all those calculations of determining what to do based on who fired the event... it's a world of hurt/pain. I'm sorry if you already understood this and were simply asking me to assist you in your masochistic tendencies ;) If you're just looking for the "intent" part of hoverIntent, you could a) pull out my code and use it in yours, or b) call a function on hoverIntent that binds/allows your desired onMouseOver/Out functions to work. Something like: $("ul").hoverIntent( inflictPain, useSafeWord ); $("ul li").mouseover( showMenu ); function inflictPain(){ var enableMenus = true; } function useSafeWord(){ var enableMenus = false; } function showMenu(){ if ( !enableMenus ) { return; } } c) use all those nifty css/xpath selectors that jQuery provides to target the menu/submenu LIs specifically with hover/hoverIntent. Of course, I don't know your exact situation. Perhaps mouseover/mouseout is the right solution. Brian. On 3/22/07, George Adamson <[EMAIL PROTECTED]> wrote:
An excellent idea that works very elegantly. Well done Brian. Might I suggest one more simple config setting... To optionally skip the following check in your handleHover function: "if (p == this){return false;}" Why? Because I'm using hoverIntent in a hierarchical menu built with *nested* <ul><li>... elements. Without the check for "p==this" I only need to apply hoverIntent to the top level menu (instead of all the submenus too, and I'm working on a page with many submenus - don't ask!). So an extra config option could be something like ignoreSubElements:true by default then you just need to change the line in handleHover() to "if (cfg.ignoreSubElements && p == this){return false;}" Kind regards, George Brian Cherne wrote: > > WHAT? > hoverIntent is a function that attempts to determine the user's intent... > like a crystal ball, only with mouse movement! It works like (and was > derived from) jQuery's built-in hover. However, instead of immediately > calling the onMouseOver function, it waits until the user's mouse slows > down > enough before calling the function. > > WHERE? > My sorely out-dated web site. > <http://cherne.net/brian/resources/jquery.hoverIntent.html> > > WHY? > To delay or prevent the accidental firing of animations or ajax calls. > Simple timers work for small areas, but if your target area is large it > may > execute regardless of intent. Also, because jQuery animations cannot be > stopped once they've started it's best not to start them prematurely. ... > and I wanted something that was easy to swap in/out with hover (so > hoverIntent returns the same "this" and event objects as hover). > > WHAT'S NEXT? > Your feedback! Tear it shreds! Tell me what you think. I would like to > keep > the script as small as possible, but if I could make this more useful (and > more likely to be used) I'm happy to make some enhancements... like... > - more compelling/verbose demo/documentation > - ability to override default settings (sensitivity, polling interval, > etc) > - option of a simple onMouseOut timer > - make it more jQuery $-friendly (first few attempts have failed) > - suggestions for code style/commenting/optimization > > > Thanks in advance, > Brian. > > _______________________________________________ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/hoverIntent-%3D-my-first-plug-in-tf3394660.html#a9610472 Sent from the JQuery mailing list archive at Nabble.com. _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
_______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/