This is a solution to the E-commerce product page challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
The code implements a web page for an e-commerce product page. The page includes a header section with a logo, navigation menu, and cart icon, as well as a product section that displays the product details, image gallery, and a button to add the product to the shopping cart.
Users should be able to:
- View the optimal layout for the site depending on their device's screen size
- See hover states for all interactive elements on the page
- Open a lightbox gallery by clicking on the large product image
- Switch the large product image by clicking on the small thumbnail images
- Add items to the cart
- View the cart and remove items from it
- Live Site URL: E-Commerce product page
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
- CSS Grid
I learnt how to manipulate an image's background image url using JS
/* collect thumbnails */
let thumbs = document.querySelectorAll(".thumbnail");
/*click event on each thumbnail */
thumbs.forEach(thumb=>{
thumb.addEventListener("click", ()=>{
var computedStyle = window.getComputedStyle(thumb);
var backgroundImage = computedStyle.getPropertyValue("background-image");
var imageUrl = backgroundImage.slice(backgroundImage.indexOf("(") + 1, backgroundImage.lastIndexOf(")")).replace(/\"/gi, "");
var imagePath = imageUrl.slice(imageUrl.lastIndexOf("/") + 1);
var finalPath = imagePath.replace("-thumbnail", "");
var finalUrl = imageUrl.slice(0, imageUrl.lastIndexOf("/") + 1) + finalPath;
main_img.style.backgroundImage = "url(" + finalUrl + ")";
})
})
JS definitley needs more work
- Website - Add your name here
- Frontend Mentor - @yourusername