video 按钮全屏

 微信小程序方法:


点击进入全屏:

showVideo1() {
    let videoContext = wx.createVideoContext('myVideo1');  //获取video的dom
    videoContext.requestFullScreen({ direction: 90 });
    videoContext.play() //视频播放
},

另一种方法

  

监听是否退出或进入全屏:(在video上绑定bindfullscreenchange事件)

screenChange(e) {
    let fullScreen = e.detail.fullScreen //值true为进入全屏,false为退出全屏
    let videoContext = wx.createVideoContext('myVideo1');
},


h5方法:
点击进入全屏:


//判断进入退出全屏
checkIsFullScreen() {
    var isFullScreen = document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen;
    return isFullScreen == undefined ? false : isFullScreen;
},
// 全屏
Screen(element) {
    if (element.requestFullscreen) {
        element.requestFullscreen();
    } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    } else if (element.oRequestFullscreen) {
        element.oRequestFullscreen();
    } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullScreen();
    } else {
        var requestFullscreen =
            document.documentElement.requestFullscreen ||
            document.documentElement.webkitRequestFullscreen ||
            document.documentElement.mozRequestFullscreen ||
            document.documentElement.requestFullScreen ||
            document.documentElement.webkitRequestFullScreen ||
            document.documentElement.mozRequestFullScreen;
        if (requestFullscreen) {
            requestFullscreen.call(document.documentElement);
        }
        //ios不处理,自动就会全屏
    }
    element.play()
},
//点读笔播放视频
productBtn() {
    let product1 = document.getElementById('product1')
    product1.play()
    this.Screen(product1)
},
document.addEventListener('fullscreenchange', () => {
    if (this.checkIsFullScreen()) {
        this.productPlay = true
        console.log("进入全屏");
    } else {
        console.log("退出全屏");
        this.productPlay = false
        document.getElementById('product1').pause()
    }
});

你可能感兴趣的:(微信小程序,小程序,h5)