script.js 983 B

1234567891011121314151617181920212223242526272829303132
  1. let dots = document.querySelectorAll(".page-dots > div");
  2. let randomSwipePage = ["left", "right", "up", "down"];
  3. let isSwipe = false;
  4. for (let d of dots) {
  5. d.onclick = function (event) {
  6. if (isSwipe) return;
  7. if (this.dataset && this.dataset.page) {
  8. let switchPage = document.querySelector(this.dataset.page);
  9. if (switchPage) {
  10. if (!this.classList.contains("active") && !switchPage.classList.contains("active")) {
  11. isSwipe = true;
  12. let active = document.querySelector(".page-dots > .active");
  13. let activePage = document.querySelector(".page.active");
  14. if (active && activePage) {
  15. active.classList.remove("active");
  16. let arrow = randomSwipePage[Math.round(Math.random() * 3)];
  17. activePage.classList.add(arrow);
  18. setTimeout(function () {
  19. activePage.classList.remove("active", arrow);
  20. isSwipe = false;
  21. }, 400);
  22. }
  23. }
  24. this.classList.add("active");
  25. switchPage.classList.add("active");
  26. }
  27. }
  28. };
  29. }