Created
April 20, 2017 11:39
-
-
Save intermundos/0486e3b6da85376acfaa473099233e54 to your computer and use it in GitHub Desktop.
Swapping images JS
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>change picture</title> | |
<script type = "text/javascript"> | |
function displayNextImage() { | |
x = (x === images.length - 1) ? 0 : x + 1; | |
document.getElementById("img").src = images[x]; | |
} | |
function displayPreviousImage() { | |
x = (x <= 0) ? images.length - 1 : x - 1; | |
document.getElementById("img").src = images[x]; | |
} | |
function startTimer() { | |
setInterval(displayNextImage, 3000); | |
} | |
var images = [], x = -1; | |
images[0] = "image1.jpg"; | |
images[1] = "image2.jpg"; | |
images[2] = "image3.jpg"; | |
</script> | |
</head> | |
<body onload = "startTimer()"> | |
<img id="img" src="startpicture.jpg"/> | |
<button type="button" onclick="displayPreviousImage()">Previous</button> | |
<button type="button" onclick="displayNextImage()">Next</button> | |
</body> | |
</html> |
menachem64
commented
May 24, 2022
<script src="https://gist.github.com/intermundos/0486e3b6da85376acfaa473099233e54.js"></script>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment