Skip to content

Commit 8e1404c

Browse files
author
mochibot
committed
tutorial wesbos#16 completed
1 parent e3ee54c commit 8e1404c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

16 - Mouse Move Shadow/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Things learned:
2+
3+
- destructuring
4+
- offsetX, offsetY

16 - Mouse Move Shadow/index-START.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ <h1 contenteditable>🔥WOAH!</h1>
3535
</style>
3636

3737
<script>
38+
let container = document.querySelector('.hero');
39+
let text = document.querySelector('h1')
40+
let walk = 300 //how far shadow go
41+
42+
function shadow(event) {
43+
let width = container.offsetWidth;
44+
let height = container.offsetHeight;
45+
//let { offsetWidth: width, offsetHeight: height } = container;
46+
let x = event.offsetX;
47+
let y = event.offsetY;
48+
//get the cursor position
49+
if (this !== event.target) {
50+
x = x + event.target.offsetLeft;
51+
y = y + event.target.offsetTop;
52+
}
53+
let xWalk = Math.round((x / width * walk) - (walk / 2))
54+
let yWalk = Math.round((y / height * walk) - (walk / 2))
55+
text.style.textShadow = `${xWalk}px ${yWalk}px 0 lightgray, ${-xWalk}px ${yWalk}px 0 gray, ${yWalk}px ${xWalk}px 0 darkgray, ${yWalk}px ${-xWalk}px 0 dimgray`;
56+
}
57+
58+
container.addEventListener('mousemove', shadow)
59+
3860
</script>
3961
</body>
4062
</html>

0 commit comments

Comments
 (0)