browser window coordinates

D

D. Alvarado

Hello,
I have an object that is 330 pixels in width. I want to position
it 330 pixels from the right edge of the viewable browser window.
Unfortunately, this isn't the JS to use:

var divObj = getDivObj(id);
divObj.left = screen.width - 330;

What is the proper call I should use? Thanks -
 
D

David Dorward

D. Alvarado said:
Hello,
I have an object that is 330 pixels in width. I want to position
it 330 pixels from the right edge of the viewable browser window.
Unfortunately, this isn't the JS to use:

var divObj = getDivObj(id);
divObj.left = screen.width - 330;

What is the proper call I should use? Thanks -

divObj.right = '330px';
 
L

Lasse Reichstein Nielsen

I have an object that is 330 pixels in width. I want to position
it 330 pixels from the right edge of the viewable browser window.

Which part of it? The left or right edge? I'll assume the closest edge
(right), as that would be the usual interpretation of distance from
something to something else.
Unfortunately, this isn't the JS to use:

var divObj = getDivObj(id);
divObj.left = screen.width - 330;

It is perfectly legal JS. It doesn't do anything because DOM objects
doesn't have a left property that means anything.

You should not use screen.width. You should position according to the
viewport, since that is all your page *can* access.
What is the proper call I should use? Thanks -

Use CSS ("position:absolute;right:300px;") or set it with Javascript & DOM:
divObj.style.position = "absolute";
divObj.style.right = "330px";

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top