Thuộc tính khối lượng HTML DOM Video trả về / đặt một số tương ứng với mức âm lượng hiện tại của phương tiện.
Cú pháp
Sau đây là cú pháp -
Trả lại khối lượng dưới dạng một số
mediaObject.volume
Đặt âm lượng đến một số
mediaObject.volume = number
LƯU Ý:Số có giá trị tối đa là ’1,0’ và nếu ‘0.0’ âm lượng video là tối thiểu.
Hãy để chúng tôi xem ví dụ về Âm lượng video tài sản -
Ví dụ
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video volume</title>
<style>
* {
padding: 2px;
margin:5px;
}
form {
width:70%;
margin: 0 auto;
text-align: center;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-DOM-Video-volume</legend>
<video id="demo" width="320" controls><source
src="http://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>
<input type="button" onclick="getTrackDetails(1)" value="Too High (-)">
<input type="button" onclick="getTrackDetails(2)" value="Too Low (+)">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var demo = document.getElementById("demo");
function getTrackDetails(val) {
if(val === 1){
if(demo.volume < 0.2)
demo.volume = 0.1;
demo.volume -= 0.1;
divDisplay.textContent = 'Volume: '+demo.volume;
}
else{
demo.volume += 0.1;
divDisplay.textContent = 'Volume: '+demo.volume;
}
}
</script>
</body>
</html> Đầu ra
Nhấp vào ‘Quá cao (-)’ nút 2 lần. Hãy xem xét điều này sẽ làm giảm nút âm lượng hai lần -
Bây giờ, hãy nhấp vào ‘Quá thấp (+)’ một lần. Cân nhắc điều này sẽ làm tăng nút âm lượng -