Design comparison
Solution retrospective
The share component becomes active on hover. However, i gave it a position absolute relative to the body causing it to change position when screen width decreases.
I tried changing the position right based on the screen width change using JS, but that didn't help as I hoped.
Community feedback
- @FexxixPosted over 1 year ago
You shouldn't need JS for share button this. Use before and after pseudo elements. This use case is like their reason for existing.
and if you did want to use JS, it should have been like this:
shareButton.addEventListener("click", showShareOptions) shareButton.addEventListener("mouseover", showShareOptions) function showShareOptions() { share.classList.add("show") shareButton.removeEventListener("click", showShareOptions) shareButton.removeEventListener("mouseover", showShareOptions) shareButton.addEventListener("click", hideShareOptions) shareButton.addEventListener("mouseleave", hideShareOptions) } function hideShareOptions() { share.classList.remove("show") shareButton.addEventListener("click", showShareOptions) shareButton.addEventListener("mouseover", showShareOptions) shareButton.removeEventListener("click", hideShareOptions) shareButton.removeEventListener("mouseleave", hideShareOptions) }
Of course, this is not the most optimal approach and can be improved.
0@FexxixPosted over 1 year ago@Fexxix actually, if you are using mousemove, there is no need for click so feel free to ignore that
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