PDA

View Full Version : How do i do this? [JavaScript] Help!



holiks
12-19-2006, 06:25 PM
:confused: http://i17.tinypic.com/2wfiqnb.gif

Please help me on this!

shachi
12-19-2006, 06:28 PM
What do you mean "change location" ?? Change it's position on the screen(like animating) or do you want it's target to change?

holiks
12-19-2006, 07:14 PM
What do you mean "change location" ?? Change it's position on the screen(like animating) or do you want it's target to change?

Change position either x/y coordinate or pixel position

shachi
12-19-2006, 07:17 PM
Oh, it's extremely easy. Just change the element's left and top properties. If you dunno how to see this example:

The js:


function move(){
some_element = document.getElementById("some_id");
some_element.style.left = "100px"; // moves the element some_element to 100px from the left
some_element.style.top = "100px"; // moves the element some_element to 100px from the top
}




<input type="button" onclick="move()" id="some_id">

holiks
12-19-2006, 09:39 PM
Oh, it's extremely easy. Just change the element's left and top properties. If you dunno how to see this example:

The js:


function move(){
some_element = document.getElementById("some_id");
some_element.style.left = "100px"; // moves the element some_element to 100px from the left
some_element.style.top = "100px"; // moves the element some_element to 100px from the top
}




<input type="button" onclick="move()" id="some_id">

Thx but Im a total newbie on this how could the final result look like^ I mean what should I write in the "some_element"? (its the button i want to be some_element?) how?!?

shachi
12-20-2006, 11:53 AM
how could the final result look like^ I mean what should I write in the "some_element"? (its the button i want to be some_element?) how?!?

Watch and learn.

Just paste it like this:



<html>
<head>
<script type="text/javascript">
function move(){
var some_element = document.getElementById("some_id");
some_element.style.left = "100px"; // moves the element some_element to 100px from the left
some_element.style.top = "100px"; // moves the element some_element to 100px from the top
}
</script>
</head>
<body>
<input type="button" onclick="move()" id="some_id" style="position: absolute;">
</body>
</html>


Again, this isn't what you wanted but just an example. It's your school project not mine.