I'd like to create a video
overlay. It works great in Chrome with https://stackoverflow.com/a/30310041/8254123, but has some issues in Safari. When I add controls
to the video
tag and want to pause the video, Safari returns this error:
Unhandled Promise Rejection: [object DOMError]
If I remove the controls
attribute it works, but I need controls
and don't want to add custom controls
.
jQuery('.video_home_1').click(function() {
if (jQuery(this).children("video").get(0).paused) {
jQuery(this).children("video").get(0).play();
jQuery(this).find(".playpause").fadeOut();
jQuery(this).find(".home_video_overlay").fadeOut();
} else {
jQuery(this).children("video").get(0).pause();
jQuery(this).find(".playpause").fadeIn();
jQuery(this).find(".home_video_overlay").fadeIn();
jQuery(this).children(".home_video_overlay").css('background', 'transparent');
}
});
.video_home_1 {
display: table;
width: auto;
position: relative;
width: auto;
height: 425px;
}
.video_home_1 .playpause {
background: url(https://www.squaresigns.com/wp-content/uploads/2017/11/play.png) 58% 50% no-repeat;
background-repeat: no-repeat;
width: 100px;
height: 100px;
position: absolute;
left: 0%;
right: 0%;
background-size: 64px 64px;
top: 0%;
bottom: 0%;
z-index: 100;
margin: auto;
border-radius: 50%;
background-color: rgba(0, 0, 0, .3);
}
.video_home_1 .home_video_overlay {
position: absolute;
z-index: 2;
top: 0;
left: 0;
width: 100%;
height: 425px;
background-repeat: no-repeat;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
cursor: pointer;
}
.video_home_1 video {
height: 425px;
width: auto;
padding-right: 4px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="video_home_1">
<video controls>
<source type="video/mp4" src="https://www.squaresigns.com/wp-content/uploads/2017/11/SquareSigns.mp4">
<source type="video/webm" src="https://www.squaresigns.com/wp-content/uploads/2017/11/SquareSigns.webm">
</video>
<div class="home_video_overlay" style="background-image: url('https://www.squaresigns.com/wp-content/uploads/2017/11/cover.png');">
<div class="playpause"></div>
</div>
</div>