JSFiddle - React, Tailwind, and code Playground

by Léo Durand

HTML

<!-- cursor -->
<div class="cursor"></div>

<!-- main -->
<div class="main">
  <h1>hello</h1>
  <p>move your cursor</p>
</div>

CSS

/* reset */ 

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  cursor: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: sans-serif;
  background: #000;
}

/* cursor */

.cursor {
  width: 1000px;
  height: 1000px;
background: rgb(255,255,255);
background: radial-gradient(circle, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%);  border-radius: 50%;
  position: absolute;
  top: 0;
  left: 0;
  transform: translateX(-50%) translateY(-50%);
}

/* main */

.main {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
}

h1 {
  font-size: 20vmin;
  font-weight: 300;
}

p {
  font-size: 4vmin;
  font-weight: 300;
}

JavaScript

const cursor = document.querySelector('.cursor');

let mouseX = 0;
let mouseY = 0;

let cursorX = 0;
let cursorY = 0;

let speed = 1; // change to increase the ease

function animate() {
    let distX = mouseX - cursorX;
    let distY = mouseY - cursorY;

    cursorX = cursorX + (distX * speed);
    cursorY = cursorY + (distY * speed);

    cursor.style.left = cursorX + 'px';
    cursor.style.top = cursorY + 'px';

    requestAnimationFrame(animate);
}


animate();

document.addEventListener('mousemove', (event) => {
    mouseX = event.pageX;
    mouseY = event.pageY;
})