9

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:

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.

I really can't figure this out, please help.

10
  • 2
    Tried doing some math and using .offset ? http://api.jquery.com/offset/ -Something like calculating the position of the moving DIV, that if offset is = or > than the offset of your DIV.... do something. Commented May 15, 2011 at 13:10
  • @roXon But would that work on any screen resolution? Because, I've made it with % Commented May 15, 2011 at 13:20
  • it should work 'cause offset is dynamic and is based on a current window (or DOM) size, calculating some element offset (Ex: top and left) in px. Commented May 15, 2011 at 13:22
  • Ohh, but would be nice if there was some easier way to do it Commented May 15, 2011 at 13:26
  • @Moiblpadde if you just want to achieve the 'DO SOMETHING' it's fine, 'cause either if your fixed (or non-fixed) element is positioned in % jQuery will count the element offset in px. respective to the elem. position inside the document. Give it a go! :) I think this could be fun! Commented May 15, 2011 at 13:26

2 Answers 2

2

You may take a look at hitTestObject

Sign up to request clarification or add additional context in comments.

Comments

0

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).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.