GoogleChromeLabs / pinch-zoom

Apache License 2.0
372 stars 54 forks source link

Prevent translation out of pinch-zoom #16

Open jnthnwn opened 5 years ago

jnthnwn commented 5 years ago

It's currently possible to completely pan the content of pinch-zoom out of view. It would be nice to have a setting that prevents the bounds of the content from being moved within the bounds of pinch-zoom.

In other words, if the content is not zoomed out, then boundaries of pinch-zoom should be equal to or contained within the boundaries of the content.

jordan-webdev commented 5 years ago

I ran into this issue, too.

dupuisv commented 4 years ago

Same

WernerRaath commented 4 years ago

Same here

dupuisv commented 4 years ago

To avoid the image moved outside the viewing windows , something like this do the job

// Correct for x
        /*
        if (topLeft.x > thisBounds.width) {
            x += thisBounds.width - topLeft.x;
        }
        else if (bottomRight.x < 0) {
            x += -bottomRight.x;
        }
        */
        if (bottomRight.x < thisBounds.width*0.8) {
            x += thisBounds.width*0.8 - bottomRight.x;
        } else if (topLeft.x > thisBounds.width*0.2) {
            x = thisBounds.width*0.2;
        }
        // Correct for y
        /*
        if (topLeft.y > thisBounds.height) {
            y += thisBounds.height - topLeft.y;
        }
        else if (bottomRight.y < 0) {
            y += -bottomRight.y;
        }
        */
        if (bottomRight.y < thisBounds.height*0.8) {
            y += thisBounds.height*0.8 - bottomRight.y;
        } else if (topLeft.y > thisBounds.height*0.2) {
            y = thisBounds.height*0.2;
        }