0

Consider the situation where div-A has a relative position to div-B (actually,div-A is hovering over div-B by different Z-Index). When the position of div-B changes, div-C is to be inserted before it and div-A is to be hidden.

The question is: how to detect the position changing of div-B?

techfoobar
  • 65,616
  • 14
  • 114
  • 135
Alex Luya
  • 9,412
  • 15
  • 59
  • 91

2 Answers2

0

That all depends on can cause the divs to move, if it's a window resizing window.onresize = function(){} or in jQuery $(window).resize(function(){});
if it's caused by user interaction (like clicks and what have you): document.body.addEventListener('click',function(){},false);, where the handler is preferably a closure of sorts, that holds the initial position of the divs in question.
If it's caused by new content inserted due to an ajax call: let the onreadystatechange handler sort it out. Again, preferably use a closure to compare the position to the initial values

There might be an easier CSS3 way, I'm no designer - so I don't really know. Also: set up a fiddle of what you've tried so far an what your page looks like. And be a bit more precise about this issue. Your question is terribly vague. Read the FAQ's

Community
  • 1
  • 1
Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
  • I prefer a universal solution,here [link]http://stackoverflow.com/questions/1882224/is-there-an-alternative-to-domattrmodified-that-will-work-in-webkit has a hint – Alex Luya Aug 11 '12 at 07:57
  • That so if you have an answer, why ask the question? If this doesn't answer your question, again, please specify when this event should fire – Elias Van Ootegem Aug 11 '12 at 11:41
-2

You can use the $.position method in jquery:

  $('#element_id').position().left;
  $('#element_id').position().top;

Just store those in a variable and then actively monitor if it changes using the setInterval() method

Wern Ancheta
  • 22,397
  • 38
  • 100
  • 139
  • Terribly brutal approach. Assuming jQ when there's nothing to suggest jQ is on the table. Telling somebody how to get the possition, but not how to use it isn't an answer. Sorry but -1 – Elias Van Ootegem Aug 10 '12 at 14:42