xmove01

slider fix

Oct 11th, 2022 (edited)
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. JS
  2.  
  3. Изменил привязку слушателей для курсора на слайдере
  4.  
  5. function cursor() {
  6.   var body = document.querySelector("body");
  7.   var cursor = document.getElementById("cursor"),
  8.     follower = document.getElementById("aura"),
  9.     links = document.getElementsByTagName("a"),
  10.     mouseX = 0,
  11.     mouseY = 0,
  12.     posX = 0,
  13.     posY = 0;
  14.  
  15.   function mouseCoords(e) {
  16.     mouseX = e.pageX;
  17.  
  18.     if (body.classList.contains("admin-bar")) {
  19.       mouseY = e.pageY - 32;
  20.     } else {
  21.       mouseY = e.pageY;
  22.     }
  23.  
  24.     cursor.classList.remove("hidden");
  25.     follower.classList.remove("hidden");
  26.   }
  27.  
  28.   gsap.to({}, 0.01, {
  29.     repeat: -1,
  30.     onRepeat: function onRepeat() {
  31.       posX += (mouseX - posX) / 11;
  32.       posY += (mouseY - posY) / 11;
  33.       gsap.set(cursor, {
  34.         css: {
  35.           left: mouseX,
  36.           top: mouseY,
  37.         },
  38.       });
  39.       gsap.set(follower, {
  40.         css: {
  41.           left: posX - 1,
  42.           top: posY - 1,
  43.         },
  44.       });
  45.     },
  46.   });
  47.  
  48.   for (var i = 0; i < links.length; i++) {
  49.     links[i].addEventListener("mouseover", function () {
  50.       cursor.classList.add("active");
  51.       follower.classList.add("active");
  52.     });
  53.     links[i].addEventListener("mouseout", function () {
  54.       cursor.classList.remove("active");
  55.       follower.classList.remove("active");
  56.     });
  57.   }
  58.  
  59.   body.addEventListener("mousemove", function (e) {
  60.     mouseCoords(e);
  61.   });
  62.   body.addEventListener("mouseout", function () {
  63.     cursor.classList.add("hidden");
  64.     follower.classList.add("hidden");
  65.   });
  66.  
  67.   if (document.querySelector(".cases-slider__swiper-slide")) {
  68.     (function () {
  69.       var slides = document.querySelectorAll(".cases-slider__swiper-slide"),
  70.         dragText = document.querySelector(".drag-text"),
  71.         skiderLink = document.querySelectorAll(".cases-slider__slider-link");
  72.  
  73.       for (var _i24 = 0; _i24 < skiderLink.length; _i24++) {
  74.         skiderLink[_i24].addEventListener("mouseover", function () {
  75.           cursor.classList.add("discover");
  76.           dragText.innerHTML = "discover";
  77.         });
  78.  
  79.         skiderLink[_i24].addEventListener("mouseout", function () {
  80.           cursor.classList.remove("discover");
  81.           dragText.innerHTML = "drag";
  82.         });
  83.       }
  84.  
  85.       slides.forEach((slide) => {
  86.         slide.addEventListener("mouseover", function () {
  87.           cursor.classList.remove("active");
  88.           cursor.classList.add("drag");
  89.           follower.style.display = "none";
  90.           dragText.style.opacity = "1";
  91.         });
  92.         slide.addEventListener("mouseout", function () {
  93.           cursor.classList.remove("drag");
  94.           follower.style.display = "block";
  95.           dragText.style.opacity = "0";
  96.         });
  97.       });
  98.     })();
  99.   }
  100. }
  101.  
  102. CSS
  103.  
  104. !!! Это задаёт расстояние между слайдами, размеры взял с настроек слайдера в js. Просто в корень CSS файла кинуть !!!
  105.  
  106. @media (min-width: 320px) {
  107.   .cases-slider__swiper-wrapper {
  108.     gap: 26px;
  109.   }
  110. }
  111. @media (min-width: 1200px) {
  112.   .cases-slider__swiper-wrapper {
  113.     gap: 100px;
  114.   }
  115. }
  116.  
  117. !!! Тут последняя строка убивает spaceBetween который вешается свайпером !!!
  118.  
  119. .cases-slider__swiper-slide {
  120.   display: -webkit-box;
  121.   display: -ms-flexbox;
  122.   display: flex;
  123.   -webkit-box-align: center;
  124.       -ms-flex-align: center;
  125.           align-items: center;
  126.   -webkit-box-orient: vertical;
  127.   -webkit-box-direction: normal;
  128.       -ms-flex-direction: column;
  129.           flex-direction: column;
  130.   -webkit-box-pack: end;
  131.       -ms-flex-pack: end;
  132.           justify-content: flex-end;
  133.   -webkit-box-align: start;
  134.       -ms-flex-align: start;
  135.           align-items: flex-start;
  136.   height: 466px;
  137.   margin-right: 0 !important;
  138. }
  139.  
  140. !!! Заблокировал user select !!!
  141.  
  142. .cases-slider__wrapper {
  143.   display: -webkit-box;
  144.   display: -ms-flexbox;
  145.   display: flex;
  146.   -webkit-box-orient: vertical;
  147.   -webkit-box-direction: normal;
  148.       -ms-flex-direction: column;
  149.           flex-direction: column;
  150.   -webkit-box-pack: center;
  151.       -ms-flex-pack: center;
  152.           justify-content: center;
  153.   height: 100%;
  154.  
  155.   -webkit-touch-callout: none;
  156.   -webkit-user-select: none;  
  157.   -khtml-user-select: none;    
  158.   -moz-user-select: none;
  159.   -ms-user-select: none;
  160.   user-select: none;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment