English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

im trying to move a picture on my screen anybody know how i can do that?
i tried this:
document.form.asd.offsetLeft += 100;
but it didnt work

2007-02-25 05:32:48 · 3 answers · asked by aryaxt 3 in Computers & Internet Programming & Design

3 answers

offset_ are read-only properties. offset_ are also relative to the parent object, so if you are trying to move the object in relation to the edge of the screen, you must recursively find the overall offset:

function overallOffsetLeft(ele)
{
var offset = 0;
while( ele.tagName.toUpperCase() != 'BODY')
{
ele = ele.parentNode;
offset += ele.offsetLeft;
}
return offset;
}

To set the position of something, you need to use CSS:

document.getElementById( 'elementID' ).style.left

Now we have:

var element = document.getElementById( 'elementID' );
element.style.left = overallOffsetLeft(element) + 'px';

Make sure the position style of your object is absolute:

#elementID {position:absolute;}

Also, document.form is a very bad way of referencing your object. The correct way would be document.getElementById('id of object').

2007-02-25 06:50:35 · answer #1 · answered by Rex M 6 · 0 1

Javascript Offsetleft

2016-11-14 06:55:15 · answer #2 · answered by Anonymous · 0 0

Go on Java's website and search it under help it might hve it..

2007-02-25 05:35:09 · answer #3 · answered by avant1991 3 · 0 2

fedest.com, questions and answers