I am creating a video player and cannot figure out how to get my video to play by clicking my playButton overlay. Ultimate goal is to get it to play by clicking the button and the button disappearing, when you want to pause you click the video and the play button reappears, but where I stand, I can't even get the video to play when I click the overlay play button.
<div class="wrapper">
<video class="video" id="video" loop controls onclick="playPause()">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" />
</video>
<div class="playButton" onclick="playPause()"></div>
</div>
Script
var bunnyVideo = document.getElementById("video");
function playPause() {
if (bunnyVideo.paused)
{
bunnyVideo.play();
}
else
{
bunnyVideo.pause();
}
}
If you change your JavaScript load type No wrap - in <body>
then it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.