私は、マウスがHTML要素内にあるかどうかを追跡しようとしています(注:子要素もあります)。
マウスオーバー/マウスアウトにアタッチし、それらをカウントするという簡単な解決法(私は今採用しています)
“マウスアウト“よりもマウスが内側にある必要があります。
しかし、私は疑問に思います。これらのイベントのいずれかが、私に不一致の数を残して、幾分(幾分奇妙な)状況下で「スキップ」することができますか?
いくつかのシンプルな試行ではこのような状況は生じませんでしたが、多くのエッジケースがあり、それらをすべて考えることはできません。誰もこのような状況に遭遇したことはありませんか?
Clarification: I have not come
across such a problem. I’m wondering if such a problem is
possible or not.
Added: A case just came to my mind – a
mouseover/mouseout on a child element which is
prevented from bubbling in its handler. Not the case for my code,
but a possibility still.
Bubbling is very likely the source of the problem. You get a
mouseout event when the mouse moves into an inner element. http://www.quirksmode.org/dom/events/mouseover.html
Suggestion, use a library. They abstract cross browser
differences between the mouseenter and mouseleave events which do
not bubble. http://api.jquery.com/mouseenter/
ライブラリを使用しない場合は、カウンタを修正する前に追跡中のdiv内にマウスがあるかどうかを確認する必要があります。あなたが持っているコードを表示すると、それを修正する方法を簡単に示すことができます。