
Design comparison
Solution retrospective
I am proud of how far I’ve come with my coding skills. What I’ll do differently next time: When adding content to the innerHTML of a div, you don’t need a div tag because document.createElement(“div”) already creates the div tag. This really stressed me out.
What challenges did you encounter, and how did you overcome them?Like I said, adding a div tag in the innerHTML was bad and debugging it was hell. I rewrote the content and harcoded it in the HTML file and compared it with the innerHTML in JS using chatGPT.
What specific areas of your project would you like help with?-
Sometimes when I place multiple orders, they may become double/appended twice. I noticed this with “vanilla panna cotta”. It’s sometimes double.
-
When confirm order is clicked, the order-confirmed box is displayed and the transparent overlay is also displayed blocking any other interaction. Now the problem is this only works on desktop view (>768px), the overlay doesn’t work when body < 768px and I didn’t even alter it on @media query. I even tried to explicitly make it show on the confirm-order event listener, yet no success. How do I fix this?
Community feedback
- @dar-juPosted 27 days ago
Hi, OffixialTrust!
Cool work!
I looked at your questions:
- I couldn't reproduce the duplication problem, everything is ok with me.
- For the block with id="overlay" add positioning -
top: 0;
andleft: 0;
Note that the images stretch when you change the screen resolution, if you don't want to precisely fit the images to the layout, then make them
object-fit: cover;
It will be looks better.Marked as helpful1 - @MarziaJaliliPosted 26 days ago
Great work!
This is how I updated the code:
#overlay { width: 100%; height: 100%; padding: 0; margin: 0; border-radius: none; position: absolute; inset: 0; background-color: rgba(0, 0, 0, 0.5); z-index: 1; display: none; }
I changed the
position
toabsolute
and set theinset
to0
to ensure it covers the entire page.This perfectly works!
😎😎😎
0@OffixialTrustPosted 26 days ago@MarziaJalili Thank you. But what does inset do in this context?
1@MarziaJaliliPosted 26 days ago@OffixialTrust As I stated above it ensures that the overlay will cover the entire page.
Because it's first positioned absolute and it's not relative to it's parent so it will take the
body
element as its parent.Therefore, the overlay will cover the
body
element completely.By the way, I downloaded your code and updated it as above and it worked out as expected. So you can apply it, too.
Let me know if you need further details!
1 - @MohamedSharqawiPosted 27 days ago
I understand the issue you’re referring to. This problem typically occurs when
setTimeout
is added to the "confirm order" button upon being clicked. If that’s the case, I’ve faced the same challenge before, and the solution is to define a global variable, such astimer
. Inside the event listener, you can useclearTimeout(timer)
to cancel any existing timeout and then assign the newsetTimeout
to thetimer
variable. Here’s how the final code would look:let timer; confirmButton.addEventListener("click", () => { clearTimeout(timer); // Clear any existing timeout timer = setTimeout(() => { // Your logic here }, 500); // Set a new timeout });
With this approach, if you click the confirm button,
clearTimeout(timer)
will prevent the previoussetTimeout
(if it exists) from executing. If no timeout is present, it will proceed with the normal logic inside thesetTimeout
. 🛠️If this is the problem you’re facing, I hope this solution helps! Let me know if it works for you. 😊
0@OffixialTrustPosted 27 days ago@MohamedSharqawi I didn't add any setTimer in my code, but I'll check the logic. Thanks.
0
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