It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

how to modify this code so the image "loop"

how to modify this code so the image "loop"

Postby jonieto on Fri Oct 05, 2007 9:54 am

Hello,

I have found this code but I would like the moving image repeat continuously around (is it also possible to add more images?)

Thank you

<html>
<head>
<script type="text/javascript">
var i=1
function starttimer()
{
document.getElementById('myimage').style.position="relative"
document.getElementById('myimage').style.left=+i
i++
timer=setTimeout("starttimer()",10)
}
function stoptimer()
{
clearTimeout(timer)
}
</script>
</head>

<body onload="starttimer()" onunload="stoptimer()">
<img id="myimage" src="smiley.gif" width="32" height="32" />
</body>
</html>
jonieto
 
Posts: 0
Joined: Fri Oct 05, 2007 9:47 am

Postby dafunkymunky on Fri Oct 05, 2007 4:37 pm

first of all dont keep on writing document.blahblah everytime. make an object first.

myimg=document.getElementById('myimage')

then you can just write myimg.style.position=whatever

and to get back the img to its initial position you'll have to check the width of the window, which can be done by

"document.body.clientWidth" (this code gives the width of the window)

check if the left postion of the img is greater than the window width.
if true set the img left position to its initial value..

Now to get the window width/height you can also use window.innerWidth but that wont work in IE(F**ked up browser)
--------DAFUNKYMUNKY--------
::THE::NECESSARY::[D]EVIL::
....errr i mean munky....
User avatar
dafunkymunky
100+ Club
 
Posts: 183
Joined: Fri Apr 08, 2005 7:32 am
Location: India

Postby dafunkymunky on Fri Oct 05, 2007 4:39 pm

and it is posiible to move more than one imgs. If you want the solution i can give it. But that'll spoil your fun to figuring it out yourself..
--------DAFUNKYMUNKY--------
::THE::NECESSARY::[D]EVIL::
....errr i mean munky....
User avatar
dafunkymunky
100+ Club
 
Posts: 183
Joined: Fri Apr 08, 2005 7:32 am
Location: India


Who is online

Users browsing this forum: No registered users and 6 guests