简体   繁体   中英

How to prevent page scrolling when pinch-zooming with Pointer Event?

I've got functionality that allows to zoom images in and out, and it works properly if there's no scrollable parent element. But when there is a scrollable parent, it doesn't work properly.

The thing is touch-action: none can't be used directly, because it prevents a page from scrolling, but I want to allow users to scroll the page only if one finger is down, and allow to zoom an image if two fingers are down.

It's strange, but the code below wouldn't work:

let fingerCount; // Assume that it has the right value

element.addEventListener("pointerdown", e => {
    if (fingerCount === 2) {
        // This line will be ignored
        element.style.touchAction = "none";
    }
});

Is there a way to combine page scrolling and pinch-zooming?

Oh, I was young and silly)) I had to do this:

// This line has to be outside of `pointerdown`
element.style.touchAction = "pan-y";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM