close
Skip to content

Commit 78d2271

Browse files
Ánderson Méndez AbelloÁnderson Méndez Abello
authored andcommitted
22, 23, 24 challenges
1 parent 25da9b1 commit 78d2271

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

‎22 - Follow Along Link Highlighter/index-START.html‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,27 @@
2626
</div>
2727

2828
<script>
29-
// 👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀
29+
30+
const triggers = document.querySelectorAll('a');
31+
const highlight = document.createElement('span');
32+
highlight.classList.add('highlight');
33+
document.body.append(highlight);
34+
35+
function highlightLink(){
36+
const linkCoords = this.getBoundingClientRect();
37+
const coords = {
38+
width: linkCoords.width,
39+
height: linkCoords.height,
40+
top: linkCoords.top + window.scrollY,
41+
left: linkCoords.left + window.scrollX
42+
};
43+
highlight.style.width = `${coords.width}px`;
44+
highlight.style.height = `${coords.height}px`;
45+
highlight.style.transform = `translate(${coords.left}px,${coords.top}px)`;
46+
47+
}
48+
triggers.forEach(trigger => trigger.addEventListener('mouseenter', highlightLink));
49+
3050
</script>
3151
</body>
3252
</html>

‎23 - Speech Synthesis/index-START.html‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,47 @@ <h1>The Voiceinator 5000</h1>
3535
const options = document.querySelectorAll('[type="range"], [name="text"]');
3636
const speakButton = document.querySelector('#speak');
3737
const stopButton = document.querySelector('#stop');
38+
39+
msg.text = document.querySelector('textarea').textContent;
40+
41+
function populateVoices() {
42+
voices = this.getVoices();
43+
voicesDropdown.innerHTML = voices
44+
.map(voice => `<option value="${voice.name}">${voice.name} ${voice.lang}</option>`).join('');
45+
}
46+
47+
function changeVoice(event) {
48+
console.log(voices);
49+
msg.voice = voices.find(voice => voice.name === this.value);
50+
console.log(msg.voice);
51+
toogle();
52+
}
53+
54+
function toogle(startOver = true) {
55+
56+
speechSynthesis.cancel();
57+
58+
if (startOver) {
59+
speechSynthesis.speak(msg);
60+
}
61+
62+
}
63+
64+
function setOption(){
65+
66+
console.log(this.name, this.value);
67+
msg[this.name] = this.value;
68+
toogle();
69+
70+
}
71+
72+
73+
speechSynthesis.addEventListener('voiceschanged', populateVoices);
74+
voicesDropdown.addEventListener('change', changeVoice);
75+
options.forEach(option => option.addEventListener('change', setOption));
76+
speakButton.addEventListener('click', toogle);
77+
stopButton.addEventListener('click', () => toogle(false));
78+
3879
</script>
3980

4081
</body>

‎24 - Sticky Nav/index-START.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h1>A story about getting lost.</h1>
6565
document.body.style.paddingTop = 0;
6666
document.body.classList.remove('fixed-nav');
6767
}
68-
}
68+
}
6969

7070
window.addEventListener('scroll', fixNav);
7171
</script>

0 commit comments

Comments
 (0)