Search This Blog

Sunday, July 6, 2014

Firebug - get absolute coordinates of Selected Element in firebug


I was searching is there any way to find the left top position of element in page fast.
without each time writing the jquery code  to fetch offset. and refesh page and debug.

i just wanted to know the position of element which i click in firebug.

and i found a great solution.

FindPostion Function :

var findpos = function findPos(obj) {
   var curleft = curtop = 0;
   if (obj.offsetParent) {
      do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
      } while (obj = obj.offsetParent);
      return [curleft,curtop];
   }
}


(paste it in Firebug, and then you have a findpos function available in the console).
For majority of simplest cases, you will have offsetParent = <body> which has zero offsets (like in the screenshots) so you don't need to add anything to offsetLeft and offsetTop. However if relative positionings take place, then you must traverse the parents.

When you select an element in Firebug, then it's available as $0 in Firebug console.
So, after mixing the two things, you can issue the commands like in the screenshot:

 photo 72b2e203-9275-432d-b694-acb4057feaa3_zpsf8b72307.png

No comments:

Post a Comment

Contact Form

Name

Email *

Message *