Created
April 26, 2013 20:32
-
-
Save dingeuwen/5470262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var img = document.getElementById('catty'); | |
img.style.position="absolute"; | |
img.style.left = "0px"; | |
max = document.width - img.width; | |
function move_right(){ | |
if(parseInt(img.style.left, 10) <= max){ | |
img.style.left = (parseInt(img.style.left, 10) + 15) + 'px'; | |
} else if(parseInt(img.style.left, 10) >= max) { | |
var timer = setInterval(move_left, 100); | |
} | |
} | |
function move_left(){ | |
if(parseInt(img.style.left, 10) >= 0){ | |
img.style.left = (parseInt(img.style.left, 10) - 15) + 'px'; | |
} else if(parseInt(img.style.left, 10) <= 0) { | |
var timer = setInterval(move_right, 100); | |
} | |
} | |
var timer = setInterval(move_right, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment