Submitted over 4 years ago
Pricing component + toggle with HTML,CSS,JS and Bootstrap
@ppasta90
Design comparison
SolutionDesign
Solution retrospective
I'm pretty sure I could have handled the js part differently, with cleaner code. Would be nice to have a feedback about that :)
Community feedback
- @HYannickPosted over 4 years ago
Hi :D nice work !
For the JS part you may not need this block :
const card = document.querySelectorAll('.card'); card.forEach((card) => { card.addEventListener('mouseover', (event) => { card.classList.add("card-over") card.addEventListener('mouseout', (e) => { card.classList.remove("card-over"); }); }); });
as you can do this in css like this instead of the "card-over" class:
.card { // your beautiful css transition: transform 0.5s ease-out; } .card:hover { transform: scale(1.1); color: white; background-image: linear-gradient(135deg, hsl(236, 72%, 79%), hsl(237, 63%, 64%)); }
For the toggle part I noticed a redundant process on the forEach. You could maybe refactor like this:
const toggleDisplay = value => el => { el.style.display = value } } toggle.addEventListener("change", (e) => { if(e.target.checked) { annual.forEach(toggleDisplay("none")) monthly.forEach(toggleDisplay("block")) } else { annual.forEach(toggleDisplay("block")) monthly.forEach(toggleDisplay("none")) } })
Hope that helps!
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord