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()
}
})
网友评论