小程序页面滚动到视频位置播放,离开暂停 记录一下

2020-03-21  本文已影响0人  茗记西岭雪

var videoContext = wx.createVideoContext('myVideo') 

    let screenWidth = wx.getSystemInfoSync().windowWidth

    let screenHeight = wx.getSystemInfoSync().windowHeight

    let topBottomPadding = (screenHeight - 170) / 2

    const videoObserve = wx.createIntersectionObserver()

    videoObserve.relativeToViewport({ bottom: -topBottomPadding, top: -topBottomPadding })

      .observe(".bottomVideo", (res) => { // ".bottomVideo" 这个我写的是视频 video 对应都 class (class='bottomVideo')

        let { intersectionRatio } = res

        if (intersectionRatio === 0) {

          //离开视界,因为视窗占比为0,停止播放

          videoContext.pause()

        } else {

          videoContext.play()

        }

      })

上一篇 下一篇

猜你喜欢

热点阅读