/    Sign up×
Community /Pin to ProfileBookmark

Bizzare possible bug?

Is anyone familiar with the onmouseout event? Seems like it doesn’t recognize nested elements inside a div?

I just discovered the problem [URL=http://www.sitepoint.com/forums/showthread.php?t=509106]here[/URL]. Anyone?

If someone comes up with a solution, I’ll be sure to point here.

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 16.2007 — Bring all your codes here, and present the problem in this thread, please. I know the solution, it is not a bug, it is only an incorrect referencing syntax.
Copy linkTweet thisAlerts:
@bals28mjkauthorOct 16.2007 — Sorry Kor, but I thought it was important to note that I was editing someone elses code:[CODE]<html>
<head>
<script type="text/javascript">

var elements = [];

elements['addInformation'] = '<a href="http://www.google.com">google</a>';
elements['linkToThisPage'] = '<p>Paragrpah Element</p>';
elements['bookmarkThisPage'] = '<h3>H3 elment</h3>';

function showDiv(element){
document.getElementById(element).innerHTML = elements['addInformation'] + elements['linkToThisPage'] + elements['bookmarkThisPage']
document.getElementById(element).style.backgroundColor="#3CF"
}

function hideDiv(element){
document.getElementById(element).innerHTML='';
document.getElementById(element).style.backgroundColor="#FFF"
}
</script>
</head>
<body>

<div onmouseover="showDiv('addInformation')"><div align="center" class="green">Add some information</div></div>

<div style="background-color:#33CCFF" align="center" id="addInformation" onmouseleave="hideDiv('addInformation')"></div>

</body>
</html>[/CODE]
Care to share the solution?
Copy linkTweet thisAlerts:
@KorOct 16.2007 — It is not a bug. First time I thought it was a reference problem (by the way, you should have also told us [I]which[/I] was the problem). Anyway, I'll do it for you.

The problem seems to be that [B]onmouseleave[/B] event was not implemented in other browsers than IE. Thus, when moving the mouse out of the new displayed div, that will not disappear in Moz, Opera, etc..., as it does in IE.

On the other hand, the simple using [B]onmouseout[/B] instead of [B]onmouseleave[/B] is not a solution, because of the event bubbling model ( when the mouse moves over a nested element inside the DIV, the browsers consider that it has left the DIV element, so the [B]onmouseout [/B]fires the function, and the DIV disapears, even you might think the mouse is still over the DIV).

A solution for this problem is to be found at:

http://www.quirksmode.org/js/events_mouse.html

on the [B]Mouseover and mouseout[/B] chapter

and

http://www.quirksmode.org/js/events_order.html

to understand the [I]event models [/I]
Copy linkTweet thisAlerts:
@bals28mjkauthorOct 16.2007 — Bring all your codes here, and present the problem in this thread, please. [/QUOTE]by the way, you should have also told us which was the problem[/QUOTE]It's not too hard to click a [URL=http://www.sitepoint.com/forums/showthread.php?t=509106]link[/URL]. Bit jealous of sitepoint?
Anyway, I'll do it for you.[/QUOTE]Do what for me? The problem seems to be that onmouseleave event was not implemented in other browsers than IE. Thus, when moving the mouse out of the new displayed div, that will not disappear in Moz, Opera, etc..., as it does in IE.[/QUOTE]I know. On the other hand, the simple using onmouseout instead of onmouseleave is not a solution, because of the event bubbling model ( when the mouse moves over a nested element inside the DIV, the browsers consider that it has left the DIV element, so the onmouseout fires the function, and the DIV disapears, even you might think the mouse is still over the DIV[/QUOTE]Yes, we know, that was al9&#8217;s original problem. A solution for this problem is to be found at:

http://www.quirksmode.org/js/events_mouse.html[/QUOTE]
Have you tested this for yourself? The example you are talking about does not work.
Copy linkTweet thisAlerts:
@KorOct 16.2007 — I use another approach.

See

http://www.alopc.ro/

Rollover the menu on "Produse" tab then mouseover/mouseout the new div
Copy linkTweet thisAlerts:
@bals28mjkauthorOct 16.2007 — Gee golly, how super.
Copy linkTweet thisAlerts:
@slaughtersOct 16.2007 — Not a huge fan of the http://www.alopc.ro/ "Produse" menue tab.

Not because it shows all the items at once, but because of the fade in/out action on mouseover. As a user the last thing I want is something that *intentionally* slows down how fast I can get information.

Sort of like the matrix "bullet-time" effect - neat the first time. Annoying as heck the 10th or 11th time.

To whom ever the developer is, I'd suggest just popp'ing the menu out as quick as possible or maybe setting some cookie to limit it to just 2 or 3 times per visit.
Copy linkTweet thisAlerts:
@KorOct 17.2007 — Not a huge fan of the http://www.alopc.ro/ "Produse" menue tab.

Not because it shows all the items at once, but because of the fade in/out action on mouseover. As a user the last thing I want is something that *intentionally* slows down how fast I can get information.

Sort of like the matrix "bullet-time" effect - neat the first time. Annoying as heck the 10th or 11th time.

To whom ever the developer is, I'd suggest just popp'ing the menu out as quick as possible or maybe setting some cookie to limit it to just 2 or 3 times per visit.[/QUOTE]

Actually, until 2 weeks ago, there was no effect, as the div was shown straight onmouseover. Later the client wanted that effect (by the way, it is not a [B]fade[/B], it is a dynamic changing of the [B]clip[/B] attribute). I accepted because, in fact, the movement is fast enough, beyond the average client reaction. More than that, the site has also a classic left menu, withe the same products as the DIV, (server-side controlled) which makes it accessible even with javascript disabled. So that I have no reason to get rid of that javascript toy. It does not affect the navigation.
Copy linkTweet thisAlerts:
@KravvitzOct 17.2007 — [url=http://dynamic-tools.net/toolbox/isMouseLeaveOrEnter/]I prefer this technique.[/url] And no, that's not a bug. :p It's a feature called event bubbling.
Copy linkTweet thisAlerts:
@KorOct 17.2007 — [url=http://dynamic-tools.net/toolbox/isMouseLeaveOrEnter/]I prefer this technique.[/url] And no, that's not a bug. :p It's a feature called event bubbling.[/QUOTE]
In fact I used a variant of that technique. I have captured the onmousemove event and verified the target elements (with all it's parentNodes till the DIV)
Copy linkTweet thisAlerts:
@KravvitzOct 17.2007 — Sort of. You're not using relatedTarget or toElement/fromElement though.
Copy linkTweet thisAlerts:
@KorOct 17.2007 — Sort of. You're not using relatedTarget or toElement/fromElement though.[/QUOTE]
Yeap. This is why I have bookmarked your link and I intend to use that code you have shown us for the future, thanks.?
Copy linkTweet thisAlerts:
@slaughtersOct 17.2007 — ... it is not a [B]fade[/B], it is a dynamic changing of the [B]clip[/B] attribute)....[/QUOTE]

OK. I'm not a fan of transition effects in menus then. For sites where there is only infrequent interaction with the menu system they are eye catching and Bosses/Business owners tend to love them for that reason.

Most of my work tends toward writing for web applications and the people who have to use a system 8 hours a day tend to hate anything which makes them wait.

Heck - they even hate drop down menus as it makes them lift their hands off the keyboard ?. That's one of the reasons I had to stop using "select" drop down form controls in favor of an AutoComplete input text box which doubles as a drop down menu. ( http://www.stansight.com/AutoComplete3.html )
Copy linkTweet thisAlerts:
@bals28mjkauthorOct 18.2007 — I prefer this technique. [/QUOTE]
[B]Kravvitz[/B], that's a good idea. Though, for some reason I get the feeling you don't prefer writing inline JavaScript ? .
Copy linkTweet thisAlerts:
@KravvitzOct 18.2007 — Correct. [url=http://www.dynamicsitesolutions.com/javascript/best-practices/#unobtrusive_javascript]It's best to avoid using inline event handlers whenever possible.[/url]
×

Success!

Help @bals28mjk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...