Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <img id="graphics" src="images/graphic1.svg" />
- <script type = "text/javascript">
- (function() { // function expression closure to contain variables
- var i = 0;
- var pics = [ "graphic1.svg", "graphic2.svg", "graphic3.svg" ];
- var el = document.getElementById('graphics'); // el doesn't change
- function toggle() {
- el.src = pics[i]; // set the image
- i = (i + 1) % pics.length; // update the counter
- }
- setInterval(toggle, 3000);
- })(); // invoke the function expression
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement