Reputation: 321
With help earlier I fixed an issue with my video player about playing a video by clicking it, but I cannot figure out how to hide the play button overlay on click. Any help will be appreciated.
HTML
<div class="video-wrapper">
<video class="video" id="bVideo" loop controls>
<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("bVideo");
function playPause() {
if (bunnyVideo.paused)
{
bunnyVideo.play();
$(".playButton").toggle();
}
else
{
bunnyVideo.pause();
$(".playButton").toggle();
}
}
bunnyVideo.addEventListener("click", playPause, false);
https://jsfiddle.net/gtoscano/ed9o52k5/2/
Upvotes: 1
Views: 10951
Reputation: 151
Here you go: https://jsfiddle.net/ed9o52k5/3/
var bunnyVideo = document.getElementById("bVideo");
function playPause() {
var el = document.getElementById("playButton");
if (bunnyVideo.paused) {
bunnyVideo.play();
el.className ="";
} else {
bunnyVideo.pause();
el.className = "playButton";
}
}
bunnyVideo.addEventListener("click", playPause, false);
Upvotes: 5