Prevent swiping between web pages in iPad Safari

后端 未结 6 1058
执念已碎
执念已碎 2020-12-30 04:30

Swiping from the left and right edges of my iPad\'s Safari browser, moves between the currently open web pages. Is there any way to prevent it?

I have tried to add <

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 04:58

    In iOS 13.4+ you can now preventDefault on "touchstart"

    Let's say we have a

    on the page that spans the entire width of the viewport and we want to prevent swipe navigation on that element.

    const element = document.querySelector('.block-swipe-nav');
    
    element.addEventListener('touchstart', (e) => {
    
        // is not near edge of view, exit
        if (e.pageX > 10 && e.pageX < window.innerWidth - 10) return;
    
        // prevent swipe to navigate gesture
        e.preventDefault();
    });
    

    I've written a short article on blocking swipe with some additional information.

提交回复
热议问题