运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>HTML DOM Events</h1> <h2>The onratechange Event</h2> <p>Use the addEventListener() method to attach a "ratechange" event to a video element.</p> <p>Use the playbackRate property to change the speed of the video:</p> <video id="myVideo" width="320" height="240" autoplay controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video><br> <button onclick="setPlaySpeed()" type="button">Set video to be play in slow motion</button> <p id="demo"></p> <script> // Get the video element: const video = document.getElementById("myVideo"); // Attach a ratechange event to the video element video.addEventListener("ratechange", myFunction); // Set the playback speed to 0.3 (slow motion) function setPlaySpeed() { video.playbackRate = 0.3; } // Alert some text when the playing speed of the video is changed function myFunction() { document.getElementById("demo").innerHTML = "The playing speed of the video was changed."; } </script> </body> </html>