Skip to content

Commit 5fe63dc

Browse files
author
vanntile
committed
Day 16
1 parent 46da1fc commit 5fe63dc

7 files changed

Lines changed: 74 additions & 107 deletions

File tree

16 - Mouse Move Shadow/index-finished.html

Lines changed: 0 additions & 66 deletions
This file was deleted.

16 - Mouse Move Shadow/index-start.html

Lines changed: 0 additions & 40 deletions
This file was deleted.

16 - Mouse Move Shadow/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Mouse Shadow</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
10+
<body>
11+
12+
<div class="hero">
13+
<h1 contenteditable>🔥WOAH!</h1>
14+
</div>
15+
<script src="script.js"></script>
16+
17+
</body>
18+
19+
</html>

16 - Mouse Move Shadow/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const hero = document.querySelector('.hero')
2+
const text = hero.querySelector('h1')
3+
const walk = 420
4+
5+
const shadow = function (e) {
6+
const {
7+
offsetWidth: width,
8+
offsetHeight: height
9+
} = hero
10+
let {
11+
offsetX: x,
12+
offsetY: y
13+
} = e
14+
15+
if (this !== e.target) {
16+
x = x + e.target.offsetLeft
17+
y = y + e.target.offsetTop
18+
}
19+
20+
const xWalk = Math.round((x / width * walk) - (walk / 2))
21+
const yWalk = Math.round((y / height * walk) - (walk / 2))
22+
23+
text.style.textShadow = `
24+
${xWalk}px ${yWalk}px 0 rgba(255, 0, 255, 0.7),
25+
${-xWalk}px ${yWalk}px 0 rgba(0, 255, 255, 0.7),
26+
${yWalk}px ${-xWalk}px 0 rgba(0, 0, 255, 0.7),
27+
${-yWalk}px ${xWalk}px 0 rgba(0, 255, 0, 0.7),
28+
${-xWalk}px ${-yWalk}px 0 rgba(255, 255, 0, 0.7)
29+
`
30+
}
31+
32+
hero.addEventListener('mousemove', shadow)

16 - Mouse Move Shadow/style.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
html {
2+
color: black;
3+
font-family: sans-serif;
4+
}
5+
6+
body {
7+
margin: 0;
8+
}
9+
10+
.hero {
11+
min-height: 100vh;
12+
display: flex;
13+
justify-content: center;
14+
align-items: center;
15+
color: black;
16+
mix-blend-mode: overlay;
17+
}
18+
19+
h1 {
20+
text-shadow: 10px 10px 0 rgba(0, 0, 0, 1);
21+
font-size: 100px;
22+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Check the course at [https://JavaScript30.com](https://JavaScript30.com)
3232
14. [x] [JavaScript References vs. Copying](https://vanntile.github.io/JavaScript30/14%20-%20JavaScript%20References%20VS%20Copying)
3333
15. [x] [LocalStorage](https://vanntile.github.io/JavaScript30/15%20-%20LocalStorage) and my
3434
[notes](./15%20-%20LocalStorage)
35-
16. [ ] Mouse Move Shadow
35+
16. [x] [Mouse Move Shadow](https://vanntile.github.io/JavaScript30/16%20-%20Mouse%20Move%20Shadow)
3636
17. [ ] Sort Without Articles
3737
18. [ ] Adding Up Times with Reduce
3838
19. [ ] Webcam Fun
61.1 KB
Loading

0 commit comments

Comments
 (0)