當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


HTML onratechange屬性用法及代碼示例

HTML onratechange屬性是事件屬性,如果更改音頻/視頻的播放速度,則會發生此事件。 playbackRate屬性用於設置或返回音頻/視頻的當前播放速度。

用法:

<element onratechange="myScript">

屬性值:此屬性包含單值腳本,該腳本在onratechanged事件屬性調用時起作用。 <audio>和<video>標簽支持此屬性。

Example:

<!DOCTYPE html>  
<html>  
  
<head>  
    <title>  
        HTML onratechange Attribute  
    </title>  
</head>  
  
<body>  
    <center>  
        <h1 style="color:green">  
        GeeksforGeks  
    </h1>  
        <h2>HTML onratechange Attribute</h2>  
  
        <video id="vidID"
            width="400" height="400"
            autoplay controls>  
            <source src=  
"https://media.geeksforgeeks.org/wp-content/uploads/20190401140735/g4g2.mp4"
                    type="video/mp4">  
        </video>  
        <br>  
  
        <button onclick="speed()" type="button">  
        Slow motion  
    </button>  
  
        <script>  
            // Get the video element with id="myVideo"  
            var x = document.getElementById("vidID");  
  
            function speed() {  
                x.playbackRate = 0.5;  
            }  
  
            x.addEventListener("ratechange", GFGfun);  
  
            function GFGfun() {  
                alert("Playing speed changed");  
            }  
        </script>  
    </center>  
</body>  
  
</html>

輸出:




支持的瀏覽器:

  • 穀歌瀏覽器
  • IE瀏覽器
  • Firefox
  • 蘋果Safari
  • Opera




相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML onratechange Attribute。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。