Medium zoom not using data-zoom-target for images with srcset
See original GitHub issueI’m using medium-zoom on some responsive images (with srcset), and I’m running into some weird behaviour. I’m using a script to calculate the most appropriate image size for the clients viewport, and I set that as the data-zoom-target
attribute.
But when zooming it seems to be zooming to the wrong size (as instead of enlarging to fill the viewport, the image shrinks). I’m not sure what exactly’s going wrong. Is this a bug, or am I doing something wrong here?
PR implementing the above: https://github.com/ismay/ismaywolff.nl/pull/718 Live url demonstrating the above: https://deploy-preview-718--ismaywolff.netlify.com/work/mould
Unzoomed:
Zoomed:
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:16 (5 by maintainers)
Top Results From Across the Web
medium-zoom | Yarn - Package Manager
medium -zoom. A JavaScript library for zooming images like Medium. version MIT license downloads gzip size no dependencies travis. Medium Zoom Demo
Read more >Srcset and Sizes: Responsive Images - AnKiT KaMbOj - Medium
It's no longer needed to serve that big hero image on a small screen. With srcset and sizes you can offer a smaller...
Read more >HTML5 picture tag issue related to zoom - Stack Overflow
While zooming images, images that are given in the media query get displayed instead of the images inside the srcset that given along...
Read more >Sending a screen capture, file, or photo - Zoom Support
The image, and any accompanying text, will be displayed to all recipients. Use the camera to take and send a photo. Sign in...
Read more >gatsby-remark-images-medium-zoom-plugin
gatsby-remark-images-medium-zoom-plugin npm version medium-zoom plugin for gatsby with Use Case gatsby-starter-bee Install How…
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the explanation, that’s quite a good way of solving this!
If you want to reduce jank when unzooming, maybe replace the
srcset
with the initialsrc
attribute before unzooming? (the one you cloned the initial image with). That’d be fewer pixels to translate back.I’ll definitely have a closer look at your implementation soon. Thanks for your research!
How about applying the new sizes attribute (something like
sizes="100vw"
) after the image has been zoomed? This way the animation would be smooth. The zoomed image might be blurry at first, but will be replaced by the appropriate sized image after download.Another approach would be setting the sizes attribute immediately, wait for the image to download, then animate but I’m not sure if it’s possible to detect that a new srcset image has been loaded.