Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 5 months ago

Article Preview Component

P
Jon•530
@jonmc89
A solution to the Article preview component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

How to toggle between states based on screen sizes, might not be the most effiecient way to do so but glad I got it to functional state.

const shareIcon = document.getElementById("shareIcon");
const cardProfileContainer = document.getElementById("cardProfileContainer");
const originalContent = document.getElementById("cardProfileInfo");
const cardProfileInfoActive = document.getElementById("cardProfileInfoActive");
const nonMobileProfileActive = document.getElementById(
  "share-active-icons-non-mob"
);
let isActive = false;

shareIcon.addEventListener("click", () => {
  isActive = !isActive;

  if (window.matchMedia("(min-width: 48em)").matches) {
    // Tablet or larger view
    nonMobileProfileActive.style.display = isActive ? "block" : "none";
  } else {
    // Mobile View
    if (isActive) {
      originalContent.style.display = "none";
      cardProfileInfoActive.style.display = "flex";
      cardProfileContainer.style.backgroundColor = "hsl(217, 19%, 35%)";
    } else {
      originalContent.style.display = "flex";
      cardProfileInfoActive.style.display = "none";
      cardProfileContainer.style.backgroundColor = "hsl(210, 46%, 95%)";
    }
  }
});

What challenges did you encounter, and how did you overcome them?

Getting the positioning of the share icons in tablet and desktop view, still not sure they are right as i was getting differnt results using inspect to live site visuals.

What specific areas of your project would you like help with?

Any suggestions I could have made this easier using JS or position of the share icons in tablets and desktop views.

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Jon's solution.

Join 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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License