How to unmute html5 video with a muted prop

后端 未结 4 2064
小鲜肉
小鲜肉 2021-02-08 18:50

I\'ve created a simple video block with muted (for mobile autostart) but now i can not change the mute state...

I used that repository , fiddle link would be great.

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-08 19:23

    Try this:

    function toggleMute() {
    
      var video=document.getElementById("myVideo");
    
      video.muted = !video.muted;
    
    }
    

    Check example here

    If your own code is not working, try adding an id to your video/element you want the click to register on and using:

    var video=document.getElementById("myVideo") ;   
    
    $(video).on("click", function(e){
      video.muted = !video.muted;
    });
    

提交回复
热议问题