<html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Video.js</title> <!-- 引入 Video.js 样式 --> <link href="https://www.hxstrive.com/cdn/libs/video.js/8.9.0/video-js.css" rel="stylesheet"> <!-- 如果您想支持 IE8(适用于 v7 之前的 Video.js 版本) --> <!-- <script src="https://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script> --> </head> <body> <!-- 视频播放器 --> <div id="container"> <video id="vid1" class="video-js vjs-big-play-centered" data-setup='{"preload":"auto","controls":true,"width":"640","height":"264px", "poster":"https://www.hxstrive.com/hxstrivedocs/source/oceans.jpg"}'> <source src="https://www.hxstrive.com/hxstrivedocs/source/oceans.mp4" type="video/mp4" /> <source src="https://www.hxstrive.com/hxstrivedocs/source/oceans.webm" type="video/webm" /> </video> </div> <p>当前音量:<label id="volume"></label></p> <p> <button onclick="add()">增加音量</button> <button onclick="reduce()">减低音量</button> </p> <!-- 引入 Video.js 库 --> <script src="https://www.hxstrive.com/cdn/libs/video.js/8.9.0/video.min.js"></script> <script> let player = videojs('vid1'); // 获取当前音量 let howLoudIsIt = player.volume(); function showVolume() { document.getElementById("volume").innerHTML = (howLoudIsIt.toFixed(2) * 100) + "%"; } showVolume(); // 增加音量 function add() { howLoudIsIt += 0.1; howLoudIsIt = Math.min(howLoudIsIt, 1); player.volume(howLoudIsIt); showVolume(); } // 减低音量 function reduce() { howLoudIsIt -= 0.1; howLoudIsIt = Math.max(howLoudIsIt, 0); player.volume(howLoudIsIt); showVolume(); } </script> </body> </html>
在线代码编辑器
HTML / CSS / JavaScript 实时预览
更多工具
运行
保存
自动执行
模板
JS 库
清空
主题
代码编辑区
字符数: 0
提示: 输入完整的 HTML 代码,需包含 DOCTYPE 声明与 html 根标签
预览效果
选择模板
取消
选择库和版本
库
版本
文件
取消
已复制到剪贴板