gpt4 book ai didi

html - 裸 CSS 模态窗口内的视频在模态窗口打开之前自动启动

转载 作者:太空宇宙 更新时间:2023-11-04 14:11:57 26 4
gpt4 key购买 nike

我正尝试按照指示在裸 CSS 模态窗口内实现视频 here到目前为止效果很好。我遇到的唯一问题是视频在模态窗口打开之前自动启动(我必须保留视频“自动启动”选项)。模态窗口关闭时视频也不会停止。

是否有任何 CSS/HTML 解决方案?如果对此没有任何 CSS/HTML 解决方案,您可以帮助我使用 javascript 解决方案。

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(){
// See if this is a touch device
if ('ontouchstart' in window){
// Set the correct [touchscreen] body class
$('body').removeClass('no-touch').addClass('touch');
// Add the touch toggle to show text when tapped
$('div.boxInner img').click(function(){
$(this).closest('.boxInner').toggleClass('touchFocus');
});
}
});
</script>

</body>

最佳答案

不,这不能通过 HTML 或 CSS 完成。

但是您可以使用 JavaScript 轻松完成此操作,并且由于您已经有了一些 jQuery 代码,我建议您也使用 jQuery 来完成此操作,因为在这种情况下,您可以通过将以下部分添加到脚本中来轻松实现此目的

jQuery

var $video = $(".modalVideo video")[0];
$video.autoplay = false;

$("a[href='#linux-c-arm_video']").click(function(){
$video.play();
});

$(".close").click(function(){
$video.pause();
});

$(function() {
// See if this is a touch device
if ('ontouchstart' in window) {
// Set the correct [touchscreen] body class
$('body').removeClass('no-touch').addClass('touch');
// Add the touch toggle to show text when tapped
$('div.boxInner img').click(function() {
$(this).closest('.boxInner').toggleClass('touchFocus');
});
}
});

var $video = $(".modalVideo video")[0];
$video.autoplay = false;

$("a[href='#linux-c-arm_video']").click(function() {
$video.play();
});

$(".close").click(function() {
$video.pause();
$video.currentTime = 0;
});
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;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<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>

</body>

更多视频

如果您希望拥有多个视频,这些视频在点击特定 ID 时动态调用,您必须进行以下更改

首先,我建议将视频操作 play()pause() 排除到一个名为 playVideo() 的函数中.

函数

function playVideo(id) {
var $video = $(id + " video")[0];
$video.autoplay = false;
$video.play();

$(".close").click(function() {
$video.pause();
$video.currentTime = 0;
});
}

需要注意的重要一点是,根据这个建议,函数需要一个参数 id。这将是您单击的链接的 ID。这是有效的,因为链接的 href 与视频的容器具有相同的 id。

最后,要仅获取应显示视频的链接的 ID,您必须将其添加到您的代码中。

$(".box a[href*='video']").click(function() {
var id = $(this).attr("href");
playVideo(id);
});

   $(function() {
// See if this is a touch device
if ('ontouchstart' in window) {
// Set the correct [touchscreen] body class
$('body').removeClass('no-touch').addClass('touch');
// Add the touch toggle to show text when tapped
$('div.boxInner img').click(function() {
$(this).closest('.boxInner').toggleClass('touchFocus');
});
}
});

$(".box a[href*='video']").click(function() {
var id = $(this).attr("href");
playVideo(id);
});

function playVideo(id) {
var $video = $(id + " video")[0];
$video.autoplay = false;
$video.play();

$(".close").click(function() {
$video.pause();
$video.currentTime = 0;
});
}
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;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<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 class="box">
<div class="boxInner">
<img src="http://dominicm.com/wp-content/uploads/2016/01/steam-arch-linux.png" />
<div class="titleBox">
<header>
Linux/Eagle/ARM
</header>
<p>
<a href="#linux-eagle_video">video</a>
<br>
<a href="#linux-eagleprogram">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>

<div id="linux-eagle_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>

</body>

关于html - 裸 CSS 模态窗口内的视频在模态窗口打开之前自动启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40838644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com