Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions 16 - Mouse Move Shadow/changi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Mouse Shadow</title>
</head>
<body>
<div class="hero">
<h1 contenteditable>🔥WOAH!</h1>
</div>

<style>
html {
color: black;
font-family: sans-serif;
}

body {
margin: 0;
}

.hero {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: black;
}

h1 {
text-shadow: 10px 10px 0 rgba(0, 0, 0, 1);
font-size: 100px;
}
</style>

<script>
const hero = document.querySelector(".hero");
const text = document.querySelector("h1");
const walk = 100;

function shadow(evt) {
const { offsetWidth: width, offsetHeight: height } = hero;
let { offsetX: x, offsetY: y } = evt;

if (this !== evt.target) {
x += evt.target.offsetLeft;
y += evt.target.offsetTop;
}

const xWalk = Math.round((x / width) * walk - walk / 2);
const yWalk = Math.round((y / height) * walk - walk / 2);

// console.log(xWalk, yWalk);

text.style.textShadow = `
${xWalk}px ${yWalk}px 0 rgba(255,0,0,0.1),
${-xWalk}px ${yWalk}px 0 rgba(0,255,0,0.1),
${xWalk}px ${-yWalk}px 0 rgba(0,0,255,0.1),
${-xWalk}px ${-yWalk}px 0 rgba(128,128,0,0.1)
`;
}

hero.addEventListener("mousemove", shadow);
</script>
</body>
</html>