Replies: 2 comments 12 replies
-
@tpdickson I'm not certain but think It looks like |
Beta Was this translation helpful? Give feedback.
-
@tpdickson I think this does what you need, it fills the width and height up to the intrinsic size of the image and scales it down without clipping it when the bounds shrink. https://stackblitz.com/edit/vitejs-vite-di5xps?file=src%2FApp.tsx&terminal=dev <ReactCompareSlider
style={{ maxHeight: '100%' }}
itemOne={
<ReactCompareSliderImage
src="https://dummyimage.com/640x360/aaa/eee?text=One"
alt="one"
style={{ objectFit: 'contain', height: 'auto', maxHeight: '100%' }}
/>
}
itemTwo={
<ReactCompareSliderImage
src="https://dummyimage.com/640x360/eee/aaa?text=Two"
alt="Two"
style={{ objectFit: 'contain', height: 'auto', maxHeight: '100%' }}
/>
}
/> |
Beta Was this translation helpful? Give feedback.
-
I'm having trouble getting the ReactCompareSlider to behave how I want it to with regards to taking up the available space, and maintaining the aspect ratio.
For example, if I have an img:
with Tailwind CSS classes
size-full
andobject-contain
, it will take up all of the available space in the parent container, up to the point that either the width or height reaches the edges, then it will automatically scale the other dimension to maintain the correct aspect ratio:(in this case, the parent container takes up the entire screen, and is an "overlay")
However, when I try to get the same behavior with ReactCompareSlider, I get all sorts of funky results:
Simply putting
size-full
andobject-contain
on the ReactCompareSlider:(I'm using the same image in itemOne and itemTwo for simple testing right now.)
Here's what it looks like:
Then if I also put
size-full
andobject-contain
on the items' img elements:It looks good initially:
But the actual slider part of it ends up overlaying the entire screen, since it is "detached" from the aspect ratio of the item components:
A side effect is that I can't click the buttons on the top right, since the slider takes up the entire screen:
How would I go about fixing this to get it to behave as I want it to?
Beta Was this translation helpful? Give feedback.
All reactions