Log in

View Full Version : Own company truck image driving across page



Crobin
09-18-2008, 12:56 PM
I have a picture of my company truck, I am looking for a script that when you access my site, the truck drives across the page. ANy one know where I can find this, or how is it done?
thanks in advance:)

rangana
09-19-2008, 01:22 AM
Hope this basic example helps:


<script type="text/javascript">
var i=10; // Initial value of the image
function move()
{
var speed=200, // Speed of the movement. The larger the value, the lower the speed.
el=document.getElementById('myimage'), // ID of the image
direction='left'; // Direction of image. Values could either be left or right

//////////// No need to edit beyond this part
el.style.position='relative';
(direction==='left')?el.style.left=i+'px':el.style.right=i+'px';
i+=10;
setTimeout('move()',speed);
}
window.onload=move;
</script>
<img src="http://rangana.moonylist.com/images/Picture1.jpg" alt="Image1" id="myimage">

Nile
09-19-2008, 01:29 AM
Why are you increasing the variable by 30? Also, you should either have it stop, dissapear, or rever directions if it reaches the end of the page.

rangana
09-19-2008, 03:52 AM
I'm not increasing the variable by 30.

I'm incrementing i variable by 10.

My example is not perfect, it's just basic, so there's flaw on it, and that's where comes the OP's learning curb.

Hope that makes sense to you Nile.

Nile
09-19-2008, 11:21 AM
Yes, rangana. My mistake, I was playing around with your example, and I made it increase by 30.

Crobin
09-19-2008, 12:30 PM
thanks guys, as soon as I get my graphic perfect, I'll try the script. :)