Reputation: 6461
I want to create a video button especially for mobile devices. So on my page there should be only a "play" button, nothing else (no video window). If I click the "play" button, the video should automatically start fullscreen in my mobile device. And if I close this window or the video is finished, then the video should again disappear.
I am trying to achieve this with the following code, but the video doesn't want to hide:
var myVideo = document.getElementById("video1");
$(document).ready(function(){
myVideo.hide();
});
function playPause() {
if (myVideo.paused)
myVideo.play();
myVideo.show();
else
myVideo.pause();
myVideo.hide();
}
<div style="text-align:center">
<button onclick="playPause()">Play</button>
<br><br>
<video id="video1" width="420">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
<source src="http://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML5 video.
</video>
</div>
Upvotes: 0
Views: 743
Reputation: 145
function playPause() {
if (myVideo.paused) {
myVideo.play();
myVideo.show();
} else {
myVideo.pause();
myVideo.hide();
}
}
You forgot the brackets by if and else. And if you load jquery it should work!
Upvotes: 1