P粉9211300672023-08-19 11:00:55
This code will create a video element with default controls. The video element will be positioned absolutely and fill the entire screen. When the video starts playing or is paused, the event listener logs a message to the console.
// 获取视频元素 const video = document.querySelector("video"); // 为视频控件添加事件监听器 video.addEventListener("play", function() { console.log("视频开始播放"); }); video.addEventListener("pause", function() { console.log("视频暂停"); });
video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
<video controls> <source id='mp4' src="http://media.w3.org/2010/05/sintel/trailer.mp4" type='video/mp4' /> </video>