检查一个 div 是否悬停在另一个 div 上 - jQuery/Javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6008546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check if one div is hovering another - jQuery/Javascript
提问by Mobilpadde
Basicly I want to check if one div is hovering another div, I've searched a lot for this, but couldn't find anything D:
基本上我想检查一个 div 是否悬停在另一个 div 上,我为此搜索了很多,但找不到任何 D:
I made a div that you can control by using the arrow keys, so now I want to check if that div is hovering another div, if so it should do something.
我制作了一个可以使用箭头键控制的 div,所以现在我想检查该 div 是否悬停在另一个 div 上,如果是,它应该做些什么。
I really can't figure this out, please help.
实在想不通,求大神帮忙。
回答by Dr.Molle
You may take a look at hitTestObject
你可以看看hitTestObject
回答by Ivan Lazarevic
It seems that you want to detect collision between two elements. So, on some event (keyDown maybe in your case) you have to detect if any of corners of first element (top-left, top-right, bottom-left, bottom-right) is within second element area (somewhere between his corners).
似乎您想检测两个元素之间的碰撞。因此,在某些事件(keyDown 可能在您的情况下)中,您必须检测第一个元素的任何角(左上角、右上角、左下角、右下角)是否在第二个元素区域内(在他的角之间的某处) )。