You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using this component with TailwindCSS and Preflight is enabled, the zoom functionality is kind of broken. I found out that the bug was due to the height: auto in preflight styles, which was preventing the hover img from taking up its full, original height.
Unfortunately, using all kinds of CSS reset declarations (inherit, revert, initial, unset) doesn't work. This is explained in https://stackoverflow.com/questions/44010645/remove-height-auto-using-css. Interestingly, the revert-layer css rule was able to fix this issue, but it's an experimental rule that seems to work only on Firefox at the moment of writing.
I came up with a solution using React, which I will share below.
Here's a picture without using this solution (mouse is in the middle):
After solution (mouse is in the middle):
Solution:
importInnerImageZoomfrom"react-inner-image-zoom";import"react-inner-image-zoom/lib/InnerImageZoom/styles.min.css";import{useEffect,useState}from"react";importstylesfrom"./ProductDetailsImage.module.css"exportconstProductDetailsImage=({ imageSrc ="", alt =""})=>{const[height,setHeight]=useState<number>();constzoomScale=1.5;useEffect(()=>{constimg=newImage();img.src=imageSrc;img.onload=()=>{setHeight(img.naturalHeight*zoomScale);}},[imageSrc]);return(<divclassName="mb-4"style={{"--image-height": `${height}px`}}><InnerImageZoomclassName={styles.productDetailsImage}src={imageSrc}zoomType="hover"zoomScale={zoomScale}imgAttributes={{ alt }}/></div>);};
When using this component with TailwindCSS and Preflight is enabled, the zoom functionality is kind of broken. I found out that the bug was due to the
height: auto
in preflight styles, which was preventing the hover img from taking up its full, original height.Unfortunately, using all kinds of CSS reset declarations (inherit, revert, initial, unset) doesn't work. This is explained in https://stackoverflow.com/questions/44010645/remove-height-auto-using-css. Interestingly, the
revert-layer
css rule was able to fix this issue, but it's an experimental rule that seems to work only on Firefox at the moment of writing.I came up with a solution using React, which I will share below.
Here's a picture without using this solution (mouse is in the middle):
After solution (mouse is in the middle):
Solution:
And here's
ProductDetailsModule.css
:The text was updated successfully, but these errors were encountered: