我想使用以下广告代码,但在关闭视频后无法将视频静音。当我关闭(另外它会在 20 秒后自动关闭)广告时,它会在后台播放视频并且仍然有声音。单击 SKIP AD 按钮后视频自动关闭时如何静音?我不了解 jQuery 或 JavaScript。你能修改我的代码并发布解决方案吗?
<script>
window.setTimeout("document.getElementById('closead').style.display='none';", 6000);
</script>
<div class="advertisement" id="closead">
<a target="_blank" rel="nofollow" href="http://www.sitename.com">
<video id="dbx" style="object-fit: fill;" autoplay="" width="100%" height="100%">
<source src="https://www.w3schools.com/tags/mov_bbb.mp4" type="video/mp4">
</video>
</a>
<button onfocus="this.blur();" class="closecss" style="position:absolute;bottom: 2px;right: 0px;z-index: 999;background: #32b02b;color: #fff;padding: 13px;border-radius: 4px;font-weight: bold;cursor: pointer;border: 1px solid #2b9825;box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.15), 0 1px 0 0 #299023, 0 2px 3px 0 rgba(0, 0, 0, 0.25);" onclick="document.getElementById('closead').style.display='none';">SKIP AD</button>
</div>
<style>
.advertisement {
position: absolute;
z-index: 99;
height: 100%;
}
</style>
最佳答案
如果能修改上面的脚本,这是个好办法。
<script>
function removeVIdeo(videoId){
var video = document.querySelector(videoId);
video.muted = true;
}
window.setTimeout(function(){
document.getElementById('closead').style.display='none';
removeVIdeo('#dbx');
},6000);
</script>
<div class="advertisement" id="closead">
<a target="_blank" rel="nofollow" href="http://www.sitename.com">
<video id="dbx" style="object-fit: fill;" autoplay="" width="100%" height="100%">
<source src="https://www.w3schools.com/tags/mov_bbb.mp4" type="video/mp4">
</video>
</a>
<button onfocus="this.blur();" class="closecss" style="position:absolute;bottom: 2px;right: 0px;z-index: 999;background: #32b02b;color: #fff;padding: 13px;border-radius: 4px;font-weight: bold;cursor: pointer;border: 1px solid #2b9825;box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.15), 0 1px 0 0 #299023, 0 2px 3px 0 rgba(0, 0, 0, 0.25);" onclick="removeVIdeo('#dbx');">SKIP AD</button>
</div>
<style>
.advertisement {
position: absolute;
z-index: 99;
height: 100%;
}
</style>
关于javascript - 如何使用 JavaScript 或 jQuery 将视频静音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50523586/