Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. <img id="graphics" src="images/graphic1.svg" />
  2.  
  3. <script type = "text/javascript">
  4. (function() { // function expression closure to contain variables
  5. var i = 0;
  6. var pics = [ "graphic1.svg", "graphic2.svg", "graphic3.svg" ];
  7. var el = document.getElementById('graphics'); // el doesn't change
  8. function toggle() {
  9. el.src = pics[i]; // set the image
  10. i = (i + 1) % pics.length; // update the counter
  11. }
  12. setInterval(toggle, 3000);
  13. })(); // invoke the function expression
  14. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement