Skip to content

Commit e89b578

Browse files
committed
Coded a replica of Stripes follow along nav.
1 parent 812bff9 commit e89b578

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

26 - Stripe Follow Along Nav/index-START.html

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ <h2>Cool</h2>
134134
opacity: 1;
135135
}
136136

137-
138-
139137
.dropdownBackground {
140138
width:100px;
141139
height:100px;
@@ -208,6 +206,39 @@ <h2>Cool</h2>
208206
</style>
209207

210208
<script>
209+
const triggers = document.querySelectorAll('.cool > li');
210+
const background = document.querySelector('.dropdownBackground');
211+
const nav = document.querySelector('.top');
212+
213+
function handleEnter() {
214+
this.classList.add('trigger-enter');
215+
setTimeout(() => this.classList.add('trigger-enter-active'), 150);
216+
background.classList.add('open');
217+
218+
const dropdown = this.querySelector('.dropdown');
219+
const dropdownCoords = dropdown.getBoundingClientRect();
220+
const navCoords = nav.getBoundingClientRect();
221+
console.log(dropdownCoords);
222+
223+
const coords = {
224+
height: dropdownCoords.height,
225+
width: dropdownCoords.width,
226+
top: dropdownCoords.top - navCoords.top,
227+
left: dropdownCoords.left - navCoords.left,
228+
};
229+
230+
background.style.setProperty('width', `${coords.width}px`);
231+
background.style.setProperty('height', `${coords.height}px`);
232+
background.style.setProperty('transform', `translate(${coords.left}px, ${coords.top}px)`);
233+
}
234+
235+
function handleLeave() {
236+
this.classList.remove('trigger-enter', 'trigger-enter-active');
237+
background.classList.remove('open');
238+
}
239+
240+
triggers.forEach(trigger => trigger.addEventListener('mouseenter', handleEnter));
241+
triggers.forEach(trigger => trigger.addEventListener('mouseleave', handleLeave));
211242
</script>
212243

213244
</body>

0 commit comments

Comments
 (0)