Based on the coordinates set the absolute position of the control (overlay) to display it accordingly. The overlay can be started any side/corner of the element.
Get the element object using JavaScript:
var obj = document.getElementById("controlelement");Get the position of the element from Left
function findPosLeft(obj)Get the position of the element from Top
{
var posLeft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
posLeft += obj.offsetLeft;
obj = obj.offsetParent;
}
}
else if (obj.x)
{
posLeft += obj.x;
}
return posLeft;
}
function findPosTop(obj)Get the position of the element from Bottom
{
var posTop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
posTop += obj.offsetTop;
obj = obj.offsetParent;
}
}
else if (obj.y)
{
posTop += obj.y;
}
return posTop;
}
function findPosBottom(obj)Get the position of the element from Right
{
var posBottom = 0;
if (obj.offsetParent)
{
posBottom += obj.offsetHeight;
while (obj.offsetParent)
{
posBottom += obj.offsetTop;
obj = obj.offsetParent;
}
}
else if (obj.y)
{
posBottom += obj.y;
posBottom += obj.height;
}
return posBottom;
}
function findPosRight(obj)
{
var posRight = 0;
if (obj.offsetParent)
{
posRight += obj.offsetWidth;
while (obj.offsetParent)
{
posRight += obj.offsetLeft;
obj = obj.offsetParent;
}
}
else if (obj.x)
{
posRight += obj.x;
posRight += obj.width;
}
return posRight;
}
No comments:
Post a Comment