javascript HTML 视频静音按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26478062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 06:00:29  来源:igfitidea点击:

HTML Video mute button

javascriptjqueryhtmlhtml5-video

提问by Kai

I have tried to create a function in javascript to mute a html video, and change the icon below to a mute icon that i have downloaded. Need Help. The javascript has to be able to work along side jquery as well

我尝试在 javascript 中创建一个函数来静音 html 视频,并将下面的图标更改为我下载的静音图标。需要帮忙。javascript 也必须能够与 jquery 一起工作

回答by Vitorino fernandes

demo - http://jsfiddle.net/victor_007/6cc9mhbb/

演示 - http://jsfiddle.net/victor_007/6cc9mhbb/

on click of the button the icon will change

单击按钮后,图标会发生变化

$("video").prop('muted', true);

$(".mute-video").click(function () {
    if ($("video").prop('muted')) {
        $("video").prop('muted', false);
        $(this).addClass('unmute-video'); // changing icon for button

    } else {
        $("video").prop('muted', true);
        $(this).removeClass('unmute-video'); // changing icon for button
    }
    console.log($("video").prop('muted'))
});

回答by Karma Hunter

The question is fairly vague, so I'm guessing that this will answer your question. If you are using video tags in HTML

这个问题相当模糊,所以我猜这会回答你的问题。如果您在 HTML 中使用视频标签

<video width="320" height="240" controls muted>
  <source src="x" type="video/x">
  <source src="x" type="x">
</video>

For Java script

对于 Java 脚本

<video id="myVideo" width="x" height="x" controls>
....
</video>
<button onclick="enableMute()" type="button">Mute sound</button>
<script>
var vid = document.getElementById("myVideo");

function enableMute() { 
    vid.muted = true;
}
</script>

As for your second questions, I don't quite understand it, please elaborate.

至于你的第二个问题,我不是很明白,请详细说明。