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

Use data-original as src #44

Open
slcr opened this issue Jul 5, 2018 · 8 comments
Open

Use data-original as src #44

slcr opened this issue Jul 5, 2018 · 8 comments

Comments

@slcr
Copy link

slcr commented Jul 5, 2018

Would it be possible to use data-original as a src for the zoom?
Right now it just zooms the src-size, which would result in a not much bigger/zoomed image when you're working with correct image sizes.

@slcr slcr changed the title use data-original as src Use data-original as src Jul 5, 2018
@spinningarrow
Copy link
Owner

I wonder what's the best way to achieve this. Maybe this is a use case for the <picture> element?

@thewebartisan7
Copy link

Did you found a solution?

I was able to use data-original by updating zoomImage:

        function zoomImage() {
            var img = document.createElement('img')
            img.onload = function () {
                fullHeight = Number(img.height)
                fullWidth = Number(img.width)
                zoomOriginal()
            }

            // Added here targetImage.getAttribute('data-original')
            img.src = targetImage.getAttribute('data-original') || targetImage.currentSrc || targetImage.src
        }

However, the result it's not the same. Something else is required in zoom calculation, because sometimes the image is attached to edge of window without margin.

@thewebartisan7
Copy link

This seem works fine:

            if (targetImage.getAttribute('data-original')) {
                targetImage.src = img.src = targetImage.getAttribute('data-original')

            } else {
                img.src = targetImage.currentSrc || targetImage.src
            }

@spinningarrow
Copy link
Owner

@thewebartisan7 thanks for looking into this! How does this behave on the first zoom for a specific image? I suppose it starts downloading the original image after the thumbnail is clicked?

@thewebartisan7
Copy link

I suppose it starts downloading the original image after the thumbnail is clicked?

Yes right. The original images it's not downloaded until you click on thumbnail.

@spinningarrow
Copy link
Owner

Got it. I think that's not ideal - one of the nice things about zoom.js is how smoothly it works and having to wait for the original image to download after clicking on the zoom takes away from that, doesn't it?

@spinningarrow
Copy link
Owner

How about using the srcset attribute for the <img> tag? The original full-size image can be the value for src and then responsive image options can be provided by srcset. I haven't tried it yet but I think that should work with zoom-vanilla.js out of the box.

@thewebartisan7
Copy link

I think that's not ideal - one of the nice things about zoom.js is how smoothly it works and having to wait for the original image to download after clicking on the zoom takes away from that, doesn't it?

I understand what you mean. I didn't think about this as my internet connection is very fast so I didn't notice any delay with animation, but it's good point to take into account. One thing that passed now in my mind is to start load the original image once users start hover over thumb.

How about using the srcset attribute for the tag? The original full-size image can be the value for src and then responsive image options can be provided by srcset. I haven't tried it yet but I think that should work with zoom-vanilla.js out of the box.

I thought this could works, and I suppose you need to use only the src here:

// Now
	img.src = targetImage.currentSrc || targetImage.src

to

// After
	img.src = targetImage.src

However for my case this would not work, because I have many small thumbs which has same size for all screen size. Not sure how to set srcset and sizes of img tag for catch all screen sizes, so the src it's never used, it's not the purpose of srcset attributes to have this usage.

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

No branches or pull requests

3 participants