Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Srcset zoom #51

Merged

Conversation

gfellerph
Copy link
Contributor

@gfellerph gfellerph commented Apr 13, 2018

This PR tries to fix the srcset zoom problem as discussed in #27. It behaves like loading a hd image with data-zoom-target and starts the zoom after the appropriate image is being loaded. I used the load event instead of polling with an interval because in a quick local test with throttled network the load event and the interval fired at similar times with a different winner every time. Also, the load event fires nicely when the image is already cached.

There are a ton of possibilities for configuring srcset and sizes so I did not spend the time to test every single one of them, allthough I think the two cases in the demo html are pretty common ones.

Closes #27.

Copy link
Owner

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! I believe it solves everything that has been discussed in #27, right?

I left a few notes mainly on the development environment (that needs to be reworked on soon because it's dodgy).

@@ -28,7 +28,7 @@

// Add zooms to a container
var containerZoom = [
mediumZoom('#zoom-default'),
mediumZoom('.zoom-default'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't edit this line since it removes the zoom of the actual demo (the one in production and not in development). We need to think of a better way to handle the different environments of the library. I've been thinking about that for a long time now but haven't got a great solution yet (we can open another issue for that).

For now, I suggest we keep mediumZoom('#zoom-default') here and add the following code snippet line 28 (we don't need to add it to containerZoom because it is only for development purpose):

mediumZoom('.zoom-srcset')

README.md Outdated
@@ -345,6 +345,14 @@ zoom.addEventListeners('show', event => {
})
```

## Compatibility

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be in this PR and needs to be reverted: git revert 2433e3d6546ee274234e9b2080724e02964902c4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that, sneaked in somehow

<figure>
<img
id="zoom-default"
class="zoom-default"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this class.


<figure>
<img
id="zoom-srcset-default"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the id.

<figure>
<img
id="zoom-srcset-default"
class="zoom-default"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the class to zoom-srcset.


<figure style="margin-right: auto; margin-left: auto; max-width: 400px">
<img
id="zoom-srcset-dtz-default"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the id.

<figure style="margin-right: auto; margin-left: auto; max-width: 400px">
<img
id="zoom-srcset-dtz-default"
class="zoom-default"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the class to zoom-srcset.

// is already in cache
const loadEventListener = target.zoomedHd.addEventListener('load', () => {
// Clean up after ourselfes
target.zoomedHd.removeEventListener('load', loadEventListener);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semicolon (;) should be omitted.

@francoischalifour
Copy link
Owner

Thank you for the new changes @tuelsch! We need to revert the changes in the README and we're ready to merge!

Copy link
Owner

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a bunch @tuelsch!

This will be part of the next release.

@francoischalifour francoischalifour merged commit 53a32ca into francoischalifour:master Jul 28, 2018
@francoischalifour
Copy link
Owner

🎉 Medium Zoom 1.0.0 has been released @tuelsch!

Check the release →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Medium zoom not using data-zoom-target for images with srcset
2 participants