cancelling mouseout event when element is overlaid

半腔热情 提交于 2019-12-12 14:35:03

问题


Hopefully this JSFiddle should illustrate the issue better than my words:

http://jsfiddle.net/pmwRc/6/

I'm displaying an absolutely positioned H4 as a label over an image map when the map is hovered. However, when the mouse pointer is moved over the H4, the image map fires a mouseout, which causes the H4 to be hidden again.

How can I prevent this? I want the label visible while the mouse is over the image map, regardless of whether it's also over the label.


回答1:


You could 'cheat' using a transparent image/layer (using your map) which is placed on top of your image.

http://jsfiddle.net/GRPQa/7/

It works using the image map coordinates.




回答2:


I know it's not exactly the same but I have modified your fiddle and got a working alternative, just without the image map;) (hover in the middle of 'G' and the first 'o')

http://jsfiddle.net/pmwRc/31/

You can use the style attribute to define coordinates in pure markup if required:

http://jsfiddle.net/pmwRc/33/




回答3:


function doSomething(e) {
    if (!e) var e = window.event;
    var tg = (window.event) ? e.srcElement : e.target;
    if (tg.nodeName != 'DIV') return;
    var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
    while (reltg != tg && reltg.nodeName != 'BODY')
        reltg= reltg.parentNode
    if (reltg== tg) return;
    // Mouseout took place when mouse actually left layer
    // Handle event
}

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



来源:https://stackoverflow.com/questions/6334654/cancelling-mouseout-event-when-element-is-overlaid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!