admin管理员组文章数量:1393114
I want to have my video automatically play and loop for me when the user scrolls to a specific area on the video element. I'm aware that I can use a JS observer to do this: however, how do I use JavaScript to add and remove 'autoplay'?
What I want my default code to be:
<video loop muted>
<source src="/videos/my_video.mp4" type="video/mp4" >
</video>
What I want to happen when the user triggers the JS observer:
<video loop muted autoplay>
<source src="/videos/my_video.mp4" type="video/mp4" >
</video>
I want to have my video automatically play and loop for me when the user scrolls to a specific area on the video element. I'm aware that I can use a JS observer to do this: however, how do I use JavaScript to add and remove 'autoplay'?
What I want my default code to be:
<video loop muted>
<source src="/videos/my_video.mp4" type="video/mp4" >
</video>
What I want to happen when the user triggers the JS observer:
<video loop muted autoplay>
<source src="/videos/my_video.mp4" type="video/mp4" >
</video>
Share
Improve this question
asked Sep 5, 2022 at 20:42
Larry-LarrieeLarry-Larriee
471 silver badge9 bronze badges
2 Answers
Reset to default 5 document.querySelector('video').autoplay = true;
document.querySelector('video').play();
or also
document.querySelector('video').pause();
本文标签: htmlAdding Autoplay To Video Element With JavascriptStack Overflow
版权声明:本文标题:html - Adding Autoplay To Video Element With Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744645188a2617358.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论