index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. var timer;
  3. var prevIndex = 0;
  4. var slideCount = 4;
  5. function modifyActive(el, add) {
  6. var element = document.getElementById(el);
  7. if (add) {
  8. element.className = element.className + " active";
  9. }
  10. else {
  11. element.className = element.className.replace("active", "");
  12. }
  13. }
  14. function setSlideShow(index, short) {
  15. if (index >= slideCount) index = 0;
  16. modifyActive("slide" + prevIndex, false);
  17. modifyActive("slide" + index, true);
  18. modifyActive("slideControl" + prevIndex, false);
  19. modifyActive("slideControl" + index, true);
  20. prevIndex = index;
  21. startTimer(short ? 8000 : 32000);
  22. }
  23. function nextSlide() { setSlideShow(prevIndex + 1, true); }
  24. function startTimer(t) { timer = setTimeout(nextSlide, t); }
  25. function slideshow_enter() { clearTimeout(timer); }
  26. function slideshow_exit () { startTimer(16000); }
  27. function slideshow_click(index) {
  28. clearTimeout(timer);
  29. setSlideShow(index, false);
  30. }
  31. window.onload = function() {
  32. var slideshow = document.getElementById("slideshow");
  33. slideshow.onmouseenter = slideshow_enter;
  34. slideshow.onmouseleave = slideshow_exit;
  35. slideCount = slideshow.children.length;
  36. startTimer(8000);
  37. };