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

Prevent over zoom beyond image natural size #40

Open
poebrand opened this issue Mar 28, 2018 · 0 comments
Open

Prevent over zoom beyond image natural size #40

poebrand opened this issue Mar 28, 2018 · 0 comments

Comments

@poebrand
Copy link

poebrand commented Mar 28, 2018

Another nice config option would be a preventOverZoom (true/false) flag. Currently it is possible to zoom beyond the bounds of the full size image's resolution, thus creating distortion.

It appears within the xscale method... you could check the natural dimensions of the image and prevent zooming beyond those bounds.

jQuery.fn.extend({
    //IE 11 and below safe way to get the natural dimensions
    getNaturalDimensions: function () {
        if (this.length === 0) {
            return null;
        }

        var img = this[0];

        //Modern browsers
        if ('naturalWidth' in img) {
            return { width: img.naturalWidth, height: img.naturalHeight };
        }

        //Older browsers
        var tempImg = new Image();
        tempImg.src = img.src;
        return { width: tempImg.width, height: tempImg.height };
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants