8000 completed challenge 26 · rohitkrai03/JavaScript30@6aa4b38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6aa4b38

Browse files
committed
completed challenge 26
1 parent 0d76c77 commit 6aa4b38

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

26 - Stripe Follow Along Nav/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,38 @@ <h2>Cool</h2>
214214
</style>
215215

216216
<script>
217+
const triggers = document.querySelectorAll('.cool > li');
218+
const background = document.querySelector('.dropdownBackground');
219+
const nav = document.querySelector('.top');
220+
221+
function handleEnter() {
222+
this.classList.add('trigger-enter');
223+
setTimeout(() => this.classList.contains('trigger-enter') && this.classList.add('trigger-enter-active'), 150);
224+
background.classList.add('open');
225+
226+
const dropdown = this.querySelector('.dropdown');
227+
const dropdownCoords = dropdown.getBoundingClientRect();
228+
const navCoords = nav.getBoundingClientRect();
229+
230+
const coords = {
231+
height: dropdownCoords.height,
232+
width: dropdownCoords.width,
233+
top: dropdownCoords.top - navCoords.top,
234+
left: dropdownCoords.left - navCoords.left
235+
};
236+
237+
background.style.setProperty('width', `${coords.width}px`);
238+
background.style.setProperty('height', `${coords.height}px`);
239+
background.style.setProperty('transform', `translate(${coords.left}px, ${coords.top}px)`);
240+
}
241+
242+
function handleLeave() {
243+
this.classList.remove('trigger-enter', 'trigger-enter-active');
244+
background.classList.remove('open');
245+
}
246+
247+
triggers.forEach(trigger => trigger.addEventListener('mouseenter', handleEnter));
248+
triggers.forEach(trigger => trigger.addEventListener('mouseleave', handleLeave));
217249
</script>
218250

219251
</body>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ No frameworks, no libraries, no wrappers... just pure VanillaJS ;)
3030
21. [x] Geolocation - [Code](./JavaScript30/21%20-%20Geolocation/index.html)
3131
22. [x] Follow Along Link Highlighter - [Demo](http://arkpod.in/JavaScript30/22%20-%20Follow%20Along%20Link%20Highlighter/index.html)
3232
23. [x] Speech Synthesis - [Demo](http://arkpod.in/JavaScript30/23%20-%20Speech%20Synthesis/index.html)
33+
24. [x] Sticky Nav - [Demo](http://arkpod.in/JavaScript30/24%20-%20Sticky%20Nav/index.html)
34+

0 commit comments

Comments
 (0)
0