我正在尝试通过将图像悬停在其上来编码转换为不同图像的图像。 通过单击图像,弹出嵌入的视频(在灯箱中)。
我尝试了几种不同的东西。这是我目前的代码。希望有人可以通过将鼠标悬停在它上面来帮助我编写一个弹出嵌入式YouTube视频的灯箱。 顺便说一下,我的目标是在这个页面上 - > https://www.garyvaynerchuk.com/
谢谢你
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 50%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .3s ease;
}
.container:hover .overlay {
opacity: 1;
}
.image2 {
display: block;
width: 50%;
height: auto;
}
</style>
</head>
<body>
<div class="container">
<a href="https://www.youtube.com/watch?v=18AgmjVPEqc">
<img src="http://politsatire.com/wp-content/uploads/2017/08/playbutton_before.png" alt="Avatar" class="image">
<div class="overlay">
<img src="http://politsatire.com/wp-content/uploads/2017/08/playbutton.png" alt="Avatar" class="image2">
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
HTML&amp; CSS不足以使用模态,你也需要Javascript才能处理所有相关事件。
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Modal Example</h2>
<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
</div>
</div>
</body>
</html>
您需要根据自己的需要调整此示例。
原始代码来自: https://www.w3schools.com/howto/howto_css_modals.asp
答案 1 :(得分:0)
使用bootstrap模式,您可以实现以下目标: