Skip to content

Commit dacdd80

Browse files
committed
17-stripe-hero-submenu complete
1 parent e9eaddc commit dacdd80

File tree

15 files changed

+1539
-0
lines changed

15 files changed

+1539
-0
lines changed

17-stripe-hero/VIDEO-URL.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(JS Video)[https://johnsmilga.com]
2+
<br />
3+
4+
(HTML&CSS Video) [https://johnsmilga.com]

17-stripe-hero/final/app.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import sublinks from './data.js';
2+
3+
const toggleBtn = document.querySelector('.toggle-btn');
4+
const closeBtn = document.querySelector('.close-btn');
5+
const sidebarWrapper = document.querySelector('.sidebar-wrapper');
6+
const sidebar = document.querySelector('.sidebar-links');
7+
const linkBtns = [...document.querySelectorAll('.link-btn')];
8+
const submenu = document.querySelector('.submenu');
9+
const hero = document.querySelector('.hero');
10+
const nav = document.querySelector('.nav');
11+
// hide/show sideabar
12+
toggleBtn.addEventListener('click', () => {
13+
sidebarWrapper.classList.add('show');
14+
});
15+
closeBtn.addEventListener('click', () => {
16+
sidebarWrapper.classList.remove('show');
17+
});
18+
19+
// set sidebar
20+
sidebar.innerHTML = sublinks
21+
.map((item) => {
22+
const { links, page } = item;
23+
return `<article >
24+
<h4>${page}</h4>
25+
<div class="sidebar-sublinks">
26+
${links
27+
.map((link) => {
28+
return `<a href="${link.url}"><i class="${link.icon}"></i>${link.label}</a>`;
29+
})
30+
.join('')}
31+
</div>
32+
</article>`;
33+
})
34+
.join('');
35+
36+
linkBtns.forEach((btn) => {
37+
btn.addEventListener('mouseover', function (e) {
38+
const text = e.currentTarget.textContent;
39+
const tempBtn = e.currentTarget.getBoundingClientRect();
40+
const center = (tempBtn.left + tempBtn.right) / 2;
41+
const bottom = tempBtn.bottom - 3;
42+
43+
const tempPage = sublinks.find((link) => link.page === text);
44+
if (tempPage) {
45+
const { page, links } = tempPage;
46+
submenu.classList.add('show');
47+
submenu.style.left = `${center}px`;
48+
submenu.style.top = `${bottom}px`;
49+
// OPTIONAL
50+
let columns;
51+
if (links.length <= 2) {
52+
columns = 'col-2';
53+
}
54+
if (links.length === 3) {
55+
columns = 'col-3';
56+
}
57+
if (links.length > 3) {
58+
columns = 'col-4';
59+
}
60+
submenu.innerHTML = `
61+
<section>
62+
<h4>${page}</h4>
63+
<div class="submenu-center ${columns}">
64+
${links
65+
.map((link) => {
66+
return `<a href="${link.url}"><i class="${link.icon}"></i>${link.label}</a>`;
67+
})
68+
.join('')}
69+
</div>
70+
</section>
71+
`;
72+
}
73+
});
74+
});
75+
76+
hero.addEventListener('mouseover', function (e) {
77+
submenu.classList.remove('show');
78+
});
79+
nav.addEventListener('mouseover', function (e) {
80+
if (!e.target.classList.contains('link-btn')) {
81+
submenu.classList.remove('show');
82+
}
83+
});

17-stripe-hero/final/data.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const sublinks = [
2+
{
3+
page: 'products',
4+
links: [
5+
{ label: 'payment', icon: 'fas fa-credit-card', url: 'products.html' },
6+
{ label: 'terminal', icon: 'fas fa-credit-card', url: 'products.html' },
7+
{ label: 'connect', icon: 'fas fa-credit-card', url: 'products.html' },
8+
],
9+
},
10+
{
11+
page: 'developers',
12+
links: [
13+
{ label: 'plugins', icon: 'fas fa-book', url: 'products.html' },
14+
{ label: 'libraries', icon: 'fas fa-book', url: 'products.html' },
15+
{ label: 'plugins', icon: 'fas fa-book', url: 'products.html' },
16+
{ label: 'billing', icon: 'fas fa-book', url: 'products.html' },
17+
],
18+
},
19+
{
20+
page: 'company',
21+
links: [
22+
{ label: 'about', icon: 'fas fa-briefcase', url: 'products.html' },
23+
{ label: 'customers', icon: 'fas fa-briefcase', url: 'products.html' },
24+
],
25+
},
26+
];
27+
28+
export default sublinks;

17-stripe-hero/final/images/hero.svg

+29
Loading

17-stripe-hero/final/images/logo.svg

+16
Loading

0 commit comments

Comments
 (0)