Skip to content

Commit 2c3879b

Browse files
committed
Completed lessons 16 and 17
xWalk in the park, baby.
1 parent d087398 commit 2c3879b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

16 - Mouse Move Shadow/index-start.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ <h1 contenteditable>🔥WOAH!</h1>
3131
</style>
3232

3333
<script>
34+
const hero = document.querySelector('.hero');
35+
const text = hero.querySelector('h1');
36+
const walk = 100; // 100px
37+
function shadow(e) {
38+
// Boo, old ES5 way
39+
// const width = hero.offsetWidth;
40+
// const height = hero.offsetHeight;
41+
// Yay, object destructuring in ES6
42+
const { offsetWidth: width, offsetHeight: height } = hero;
43+
let { offsetX: x, offsetY: y } = e;
44+
45+
if (this !== e.target) {
46+
x = x + e.target.offsetLeft;
47+
y = y + e.target.offsetTop;
48+
}
49+
50+
const xWalk = Math.round((x / width * walk) - (walk / 2));
51+
const yWalk = Math.round((y / width * walk) - (walk / 2));
52+
53+
console.log(xWalk, yWalk);
54+
55+
text.style.textShadow = `
56+
${xWalk}px ${yWalk}px 0 rgba(255,0,255,0.7),
57+
${xWalk * -1}px ${yWalk}px 0 rgba(0,0,255,0.7),
58+
${yWalk}px ${xWalk * -1}px 0 rgba(255,0,0,0.7),
59+
${yWalk * -1}px ${xWalk}px 0 rgba(0,255,255,0.7)
60+
`;
61+
}
62+
hero.addEventListener('mousemove', shadow);
3463
</script>
3564
</body>
3665
</html>

17 - Sort Without Articles/index-START.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@
4343
<ul id="bands"></ul>
4444

4545
<script>
46-
const bands = ['The Plot in You', 'The Devil Wears Prada', 'Pierce the Veil', 'Norma Jean', 'The Bled', 'Say Anything', 'The Midway State', 'We Came as Romans', 'Counterparts', 'Oh, Sleeper', 'A Skylit Drive', 'Anywhere But Here', 'An Old Dog'];
46+
const bands = ['The Plot in You', 'The Devil Wears Prada', 'Pierce the Veil', 'Norma Jean', 'The Bled', 'Say Anything', 'The Midway State', 'We Came as Romans', 'Counterparts', 'Oh, Sleeper', 'A Skylit Drive', 'Anywhere But Here', 'An Old Dog'];
4747

48+
function strip(bandName) {
49+
return bandName.replace(/^(a |the |an )/i, '').trim();
50+
}
51+
52+
const sortedBands = bands.sort((a,b) => strip(a) > strip(b) ? 1 : -1);
53+
54+
document.getElementById('bands').innerHTML =
55+
sortedBands
56+
.map(band => `<li>${band}</li>`)
57+
.join('');
4858

4959
</script>
5060

0 commit comments

Comments
 (0)