How would I add an overlay div on top of a slide image? #223
-
Hi there, thanks for creating this awesome library! I'm exploring the documentation and I'm not sure how to approach this issue. I am building an application where users can be tagged, and I want to display their names on top of an image, similar to how social networks like Instagram display tags on images. To do that, I'd need to have a div that will be absolutely positioned and sit on top of the image. Then, I can do my logic and display tags on appropriate position. My initial strategy was to use a custom slide. That won't work for me, as I'm also interested in using the Zoom plugin. What would be the appropriate strategy here? Creating a custom plugin myself? Any help would be greatly appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Hi there! Are you trying to position the tags relative to the image (e.g. bottom left corner of the image)? or relative to the lightbox viewport? The latter is pretty trivial to implement with render={{
slideFooter: ({ slide }) => (
<div style={{ position: "absolute", bottom: 0, left: 0, padding: 10, color: "red" }}>Image tags</div>
),
}} However, adding an overlay on top of an image that matches its dimensions isn't trivial in the current version (especially with Zoom plugin). You could probably use the following approach if you are not using responsive images (images with function ImageWithOverlay({ slide, offset, rect }: RenderSlideProps<SlideImage>) {
const [loaded, setLoaded] = React.useState(false);
return (
<span style={{ position: "relative" }}>
<ImageSlide
slide={slide}
offset={offset}
rect={rect}
style={{ display: "block" }}
onLoad={() => setLoaded(true)}
/>
{loaded && <div style={{ position: "absolute", bottom: 0, left: 0, color: "red" }}>Image tag</div>}
</span>
);
} render={{
slide: ({ slide, offset, rect }) =>
isImageSlide(slide) ? <ImageWithOverlay {...{ slide, offset, rect }} /> : undefined,
}} Please let me know if the above addresses your case. |
Beta Was this translation helpful? Give feedback.
@bojandurmic, here is an alternative implementation that I believe addresses the issue I was seeing in my tests.