simplecarousel.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. (function(document) {
  2. document.addEventListener("DOMContentLoaded", function(event) {
  3. var carouselButtons = document.getElementsByClassName("image-carousel");
  4. for(var i = 0, button = carouselButtons[i]; button = carouselButtons[i]; i++) {
  5. //button.addEventListener("click", cycleImages);
  6. button.addEventListener("click", cycleVideos);
  7. }
  8. });
  9. function cycleImages(event) {
  10. var parent = event.currentTarget.parentNode;
  11. var images = parent.getElementsByTagName('img');
  12. var button = parent.getElementsByTagName('button')[0];
  13. var firstImage = images[0];
  14. firstImage.style.display = "none";
  15. var nextImage = images[1];
  16. nextImage.style.display = "inline-block";
  17. parent.insertBefore(firstImage, button);
  18. }
  19. function cycleVideos(event) {
  20. var parent = event.currentTarget.parentNode;
  21. var videos = parent.getElementsByTagName('video');
  22. var button = parent.getElementsByTagName('button')[0];
  23. var firstVideo = videos[0];
  24. firstVideo.style.display = "none";
  25. var nextVideo = videos[1];
  26. nextVideo.style.display = "inline-block";
  27. parent.insertBefore(firstVideo, button);
  28. }
  29. })(document);