video.js全屏
时间: 2023-12-08 15:38:31 浏览: 108
以下是使用video.js实现全屏的方法:
```javascript
var player = videojs('my-video');
// 进入全屏
function requestFullScreen() {
var containerEl = player.el();
if (containerEl.requestFullscreen) {
containerEl.requestFullscreen();
} else if (containerEl.webkitRequestFullscreen) {
containerEl.webkitRequestFullscreen();
} else if (containerEl.mozRequestFullScreen) {
containerEl.mozRequestFullScreen();
} else if (containerEl.msRequestFullscreen) {
containerEl.msRequestFullscreen();
}
}
// 退出全屏
function exitFullScreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen(); } else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
// 监听全屏状态变化
player.on('fullscreenchange', function() {
if (player.isFullscreen()) {
console.log('进入全屏');
} else {
console.log('退出全屏');
}
});
```
其中,`requestFullScreen()`函数用于进入全屏,`exitFullScreen()`函数用于退出全屏,`fullscreenchange`事件用于监听全屏状态变化。
阅读全文