Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yitonghe00/89303c08c6ac734eee45c590d9375faf to your computer and use it in GitHub Desktop.
Save yitonghe00/89303c08c6ac734eee45c590d9375faf to your computer and use it in GitHub Desktop.
<style>
.trail { /* className for the trail elements */
position: absolute;
height: 6px; width: 6px;
border-radius: 3px;
background: teal;
}
body {
height: 300px;
}
</style>
<script>
const dots = [];
let index = 0;
for (let i = 0; i < 10; i++) {
const dot = document.createElement("div");
dot.className = 'trail';
dot.style.display = 'none';
document.body.appendChild(dot);
dots.push(dot);
}
window.addEventListener("mousemove", (event) => {
const dot = dots[index];
dot.style.display = 'initial';
dot.style.left = (event.pageX - 3) + 'px';
dot.style.top = (event.pageY - 3) + 'px';
index = (index + 1) % dots.length;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment