简体   繁体   中英

Full Screen event on Touch not working on Chrome

In my mobile app I want to toggle full screen when user is swiping up.
So when touchend event is triggered I'm calling document.documentElement.webkitRequestFullScreen();
The problem is that it doesn't works for me in mobile Chrome 56+.

Here is example. https://jsfiddle.net/ibmw/tnncaxj0/6/

The interest part is: this issue appearing only when you make touchmove between touchstart and touchend.

In console I've got an error:

Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture. document.documentElement.webkitRequestFullScreen();

Does anyone know how to struggle it?

You have to call preventDefault() on touchmove, and pass new option to addEventListener() . It's works for me:

addEventListener('touchmove', onTouchMove, {passive: false});

function onTouchMove(e) {
  e.preventDefault
}

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