Created
May 17, 2022 05:30
-
-
Save yitonghe00/89303c08c6ac734eee45c590d9375faf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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