demo.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * demo.js
  3. * http://www.codrops.com
  4. *
  5. * Licensed under the MIT license.
  6. * http://www.opensource.org/licenses/mit-license.php
  7. *
  8. * Copyright 2017, Codrops
  9. * http://www.codrops.com
  10. */
  11. {
  12. setTimeout(() => document.body.classList.add('render'), 60);
  13. const navdemos = Array.from(document.querySelectorAll('nav.demos > .demo'));
  14. const total = navdemos.length;
  15. const current = navdemos.findIndex(el => el.classList.contains('demo--current'));
  16. const navigate = (linkEl) => {
  17. document.body.classList.remove('render');
  18. document.body.addEventListener('transitionend', () => window.location = linkEl.href);
  19. };
  20. navdemos.forEach(link => link.addEventListener('click', (ev) => {
  21. ev.preventDefault();
  22. navigate(ev.target);
  23. }));
  24. /*
  25. document.addEventListener('keydown', (ev) => {
  26. const keyCode = ev.keyCode || ev.which;
  27. let linkEl;
  28. if ( keyCode === 37 ) {
  29. linkEl = current > 0 ? navdemos[current-1] : navdemos[total-1];
  30. }
  31. else if ( keyCode === 39 ) {
  32. linkEl = current < total-1 ? navdemos[current+1] : navdemos[0];
  33. }
  34. else {
  35. return false;
  36. }
  37. navigate(linkEl);
  38. });
  39. */
  40. }