Set Left,Top at different screen resolution by JavaScript

I have a task to dispaly a div starts from the left position of some other control.

I had searched on so many sites but, unfortunately I have not found any good solution.

But, finally I found a solution, as I know the default left on 1024 x 768 is "251" so I use this as a gift of god.

Following is the code how to do that:-

var obj=document.getElementById("a1");
var int_left=screen.width; // get Pixel size of screen
if (int_left>1024)
{
int_left=int_left-1024; // get width other then 1024
int_left=int_left/2; get the first half of width
int_left=int_left+251; add first half to the width
}
else
{
int_left=253;
}

obj.style.left=int_left;

If you have any doubts please let me know.
Share:

No comments: