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:
No comments:
Post a Comment