While building a landing page for work, I had to include a couple of images of the product.
The app is an enterprise application
with lots happening on it and a 1/4 screen width screenshot wasn’t going to cut it. While the
screenshot looked good on the site, the text content of the screenshot was barely visible. So, to provide value to
an interested visitor on the site, I wanted to expand the image on hover.
What I did
Figure out if the screen is a desktop
Use tailwind group utility to figure out when to show text/icon that indicates the image is clickable
Use a state variable to hold whether the image is expanded or collapsed and scale accordingly
Add a backdrop that takes up the entire screen but has a zIndex less than the image
If you don’t add flex when the image is expanded, it won’t resize correctly and the scroll position is lost