Advertisement
salmancreation

js custom cursor pointer style

Aug 29th, 2023
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  // custom coursor
  2.   if ($(".custom-cursor").length) {
  3.     var cursor = document.querySelector(".custom-cursor__cursor");
  4.     var cursorinner = document.querySelector(".custom-cursor__cursor-two");
  5.     var a = document.querySelectorAll("a");
  6.  
  7.     document.addEventListener("mousemove", function (e) {
  8.       var x = e.clientX;
  9.       var y = e.clientY;
  10.       cursor.style.transform = `translate3d(calc(${e.clientX}px - 50%), calc(${e.clientY}px - 50%), 0)`;
  11.     });
  12.  
  13.     document.addEventListener("mousemove", function (e) {
  14.       var x = e.clientX;
  15.       var y = e.clientY;
  16.       cursorinner.style.left = x + "px";
  17.       cursorinner.style.top = y + "px";
  18.     });
  19.  
  20.     document.addEventListener("mousedown", function () {
  21.       cursor.classList.add("click");
  22.       cursorinner.classList.add("custom-cursor__innerhover");
  23.     });
  24.  
  25.     document.addEventListener("mouseup", function () {
  26.       cursor.classList.remove("click");
  27.       cursorinner.classList.remove("custom-cursor__innerhover");
  28.     });
  29.  
  30.     a.forEach((item) => {
  31.       item.addEventListener("mouseover", () => {
  32.         cursor.classList.add("custom-cursor__hover");
  33.       });
  34.       item.addEventListener("mouseleave", () => {
  35.         cursor.classList.remove("custom-cursor__hover");
  36.       });
  37.     });
  38.   }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement