取消静音背景视频的按钮

时间:2020-11-03 16:49:43

标签: javascript html video

尝试使用自带的视频背景英雄(在带elemnetor的WordPress中为wordpress),该英雄在加载时会自动播放但没有声音,因为应使其符合ADA规范并受到某些Web浏览器的支持,而应将其静音。

我想知道是否可以有一个按钮/图标来取消声音的静音,但同时又重新启动视频,以便30秒的信息和声音从头开始?

问题:
我已将其设置为无声音自动播放,并使用此技术和此代码(https://elementorcodes.com/elementor-video-background-sound-button/)添加了一个图标,但是如何同时触发重新启动?

代码:

document.addEventListener('DOMContentLoaded', function() {
var toggleSoundButton = document.querySelector('.fa-volume-mute');
var heroBackgroundVideo = document.querySelector('.herosection video');
toggleSoundButton.addEventListener('click', function (event) {

if (heroBackgroundVideo.muted !== false){
heroBackgroundVideo.muted=false;
toggleSoundButton.classList.add('fa-volume-up');
} else {
heroBackgroundVideo.muted=true;
toggleSoundButton.classList.remove('fa-volume-up');
} }); });
</script>

1 个答案:

答案 0 :(得分:1)

heroBackgroundVideo.currentTime = 0;
heroBackgroundVideo.play();
相关问题