My goal is to incorporate a video into a minimalist CSS modal window, following the guidance provided here. While the setup works well overall, I encounter a issue where the video starts playing before the modal window is opened (I need to maintain the "autostart" option). Additionally, the video continues playing even after the modal window is closed.
Are there any potential solutions in CSS/HTML to address this challenge? If not, suggestions for JavaScript solutions would be greatly appreciated.
body{
margin: 0;
padding-left: 10%;
padding-right: 10%;
padding-top: 2%;
padding-bottom: 1%;
}
.boxspace {
overflow: hidden;
}
.box {
float: left;
position: relative;
width: 16.6666%;
padding-bottom: 16.6666%;
}
.boxInner {
position: absolute;
left: 2%;
right: 2%;
top: 2%;
bottom: 2%;
overflow: hidden;
border: thin solid #969696;
border-radius: 4%;
}
.boxInner img {
width: 100%;
}
.boxInner .titleBox {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin-bottom: -42%;
background: #000000;
background: rgba(0, 0, 0, 0.8);
color: #FFFFFF;
padding-top: 2%;
padding-bottom: 2%;
padding-left: 2%;
padding-right: 2%;
text-align: center;
font-size: 1.2vw;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.boxInner .titleBox header{
color: #FFFFFF;
font-size: 1.4vw;
}
.boxInner .titleBox p{
color: #FFFFFF;
font-size: 1.0vw;
}
body.no-touch .boxInner:hover .titleBox, body.touch .boxInner.touchFocus .titleBox {
margin-bottom: 0px;
}
.modalVideo {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,0.8);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalVideo:target {
opacity:1;
pointer-events: auto;
}
.modalVideo > div {
position: relative;
margin-top: 2vw;
margin-left: 20vw;
margin-right: 20vw;
padding-top: 1vw;
padding-bottom: 1vw;
padding-left:1.05vw;
padding-right:1.05vw;
border-radius: 1vw;
background: #ffffff;
font-size: 1.1vw;
}
.modalVideo video {
width: 100%;
}
.modalProgram {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,0.8);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalProgram:target {
opacity:1;
pointer-events: auto;
}
.modalProgram > div {
position: relative;
margin-top: 2vw;
margin-left: 10vw;
margin-right: 10vw;
padding-top: 1vw;
padding-bottom: 1vw;
padding-left:2vw;
padding-right:2vw;
border-radius: 1vw;
background: #ffffff;
font-size: 1.1vw;
}
.close {
background: #FF0000;
color: #FFFFFF;
position: absolute;
top: 4vw;
right: -4.2vw;
text-align: center;
padding-left:0.75vw;
padding-right:0.75vw;
padding-bottom:0.25vw;
padding-top:0.25vw;
text-decoration: none;
border-top-left-radius: 0vw;
border-bottom-left-radius: 0vw;
border-top-right-radius: 1vw;
border-bottom-right-radius: 1vw;
}
.close:hover {
background: #464646;
}
<body class="no-touch">
<div class="boxspace">
<!-- tiles: -->
<div class="box">
<div class="boxInner">
<img src="http://dominicm.com/wp-content/uploads/2016/01/steam-arch-linux.png" />
<div class="titleBox">
<header>
Linux/C/ARM
</header>
<p>
<a href="#linux-c-arm_video">video</a><br>
<a href="#linux-c-arm_program">program</a><br>
prijavnica
</p>
</div>
</div>
</div>
</div>
<!-- end of tiles and wrap -->
<!--Linux/C/ARM - program-->
<div id="linux-c-arm_program" class="modalProgram">
<div>
<a href="#close" title="Close" class="close">close</a>
<h3>HEADER</h3>
<p>
Paragraph
</p>
</div>
</div>
<!--Linux/C/ARM - video-->
<div id="linux-c-arm_video" class="modalVideo">
<div>
<a href="#close" title="Close" class="close">close</a>
<video controls autoplay>
<source src="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" type="video/mp4">
</video>
</div>
</div>
<!-- end "no-touch" parameter for body-->
<script type="text/javascript">
$(function(){
// Determine if this is a touch device
if ('ontouchstart' in window){
// Apply the correct [touchscreen] body class
$('body').removeClass('no-touch').addClass('touch');
// Include the touch toggle to display text when tapped
$('div.boxInner img').click(function(){
$(this).closest('.boxInner').toggleClass('touchFocus');
});
}
});
</script>
</body>