francoischalifour / medium-zoom

🔎🖼 A JavaScript library for zooming images like Medium
https://medium-zoom.francoischalifour.com
MIT License
3.58k stars 160 forks source link

fix: use currentSrc for imgs in <picture> tags #194

Closed fennifith closed 1 year ago

fennifith commented 1 year ago

Summary

Issue #174 details a lack of support for differences in the selected image within a <picture> tag. In this case, the image's currentSrc reflects which of the available sources the browser decided to use.

In my case, the <img> tags lack any src whatsoever, so when used outside of the <picture> tags they will not display any image.

Result

I took a slightly more naive solution than what is described in #174 - any <img> tag in a <picture> structure now sets zoomed.src = original.currentSrc after cloning the element. This ensures that the zoomed image will reflect the same source as what was originally displayed in the <picture> tag, and eliminates any flicker in the transition when used with data-zoom-src.

codesandbox-ci[bot] commented 1 year ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a490d0b50ff16e26a54f845824108edcc741c3be:

Sandbox Source
@medium-zoom/vanilla-example Configuration
francoischalifour commented 1 year ago

Closes #174.

francoischalifour commented 1 year ago

🎉 This was released in v1.0.8.

fennifith commented 1 year ago

Awesome - thank you! \:D