revision:
The onratechange attribute defines a script to be run when the playing speed of the audio/video is changed (like when a user switches to a slow motion or fast forward mode).
Supported HTML tags: <audio> and <video>.
<element onratechange="script"></element>
script: this attribute contains a "single value script", which works when the onratechange event attribute is called.
example
Change the speed of the audio
codes:
<audio style="margin-left:3vw;" id="myAudio" controls onratechange="audioSpeed()"> <source src="../../pics/horse.wav" type="audio/wav"> Your browser does not support the audio element. </audio> <p class="spec" id="demo">Change the speed of the audio</p> <input style="margin-left:3vw;" type="range" min="0.5" max="3" step="0.1" value="1" oninput="changeRate(this)"> <script> function audioSpeed() { document.getElementById("demo").innerHTML = "The audio's speed is " + document.getElementById("myAudio").playbackRate; } function changeRate(obj) { document.getElementById("myAudio").playbackRate = obj.value; } </script>
example
Change the speed of the video
codes:
<video style="margin-left:3vw;" id="myVideo" width="320" height="176" controls onratechange="videoSpeed()"> <source src="../../pics/Wuzhen-20-10_02.mp4" type="video/mp4"> Your browser does not support HTML5 video. </video> <p class="spec" id="demo_A">Change the speed of the video</p> <input style="margin-left:3vw;" type="range" min="0.1" max="3" step="0.1" value="1" oninput="rateChange(this)"> <script> function videoSpeed() { document.getElementById("demo_A").innerHTML = "The video's speed is " + document.getElementById("myVideo").playbackRate; } function rateChange(obj) { document.getElementById("myVideo").playbackRate = obj.value; } </script>
The onreset event occurs when a form is reset.
Supported HTML tags: <form>
<element onreset="script"></element>
script: this attribute contains a "single value script", which works when the onreset event attribute is called.
example
When you reset the form, a function is triggered which alerts some text.
codes:
<p class="spec">When you reset the form, a function is triggered which alerts some text.</p> <form style="margin-left:3vw;" onreset="resetFunction()"> <p class="spec">Enter name: <input type="text"></p> <input type="reset"> </form> <script> function resetFunction() { alert("The form was reset"); } </script>
example
When you reset the form, a function is triggered which outputs some text.
codes:
<p class="spec">When you reset the form, a function is triggered which outputs some text.</p> <form style="margin-left:3vw;" onreset="formReset()"> <p class="spec">enter name: <input type="text"></p> <input type="reset"> </form> <p class="spec" id="demo"></p> <script> function formReset() { document.getElementById("demo").innerHTML = "The form was reset"; } </script>
The onresize event occurs when the browser window has been resized.
Supported HTML tags: <body>
To get the size of an element, use the "clientWidth", "clientHeight", "innerWidth", "innerHeight", "outerWidth", "outerHeight", "offsetWidth" and/or "offsetHeight" properties.
<element onresize="script"></element>
script: this attribute contains a "single value script", which works when the onreset event attribute is called.
example
Try to resize the browser window to display the windows height and width.
codes:
<body onresize="sizeFunction()"> <p class="spec">Try to resize the browser window to display the windows height and width.</p> <p class="spec" id="demo_AA"></p> <script> function sizeFunct() { var w = window.outerWidth; var h = window.outerHeight; var txt_A = "Window size: width=" + w + ", height=" + h; document.getElementById("demo_AA").innerHTML = txt_A; } </script>
example
This example uses the addEventListener() method to attach a "resize" event on the window object.
Try to resize the browser window.
Window resized 0 times.
codes:
<p class="spec">This example uses the addEventListener() method to attach a "resize" event on the window object.</p> <p class="spec">Try to resize the browser window.</p> <p class="spec">Window resized <span id="demo+AA">0</span> times.</p> <script> window.addEventListener("resize", windowResize); var x = 0; function windowResize() { var txt_B = x += 1; document.getElementById("demo+A").innerHTML = txt_B; } </script>