gpt4 book ai didi

html - 具有悬停效果的图像,当您在 youtube 视频中单击时,应该会在灯箱中弹出

转载 作者:行者123 更新时间:2023-11-28 03:16:33 24 4
gpt4 key购买 nike

我正在尝试编写一个图像,通过将鼠标悬停在图像上,该图像会变成不同的图像。通过单击图像,会弹出嵌入的视频(在灯箱中)。

我尝试了几种不同的方法。那是我目前的代码。希望有人可以帮助我编写一个灯箱,通过将鼠标悬停在它上面来弹出带有嵌入式 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>

最佳答案

HTML 和 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">&times;</span>
<p>Some text in the Modal..</p>
</div>

</div>

</body>
</html>

您需要根据您的需要调整此示例。

原始代码来自: https://www.w3schools.com/howto/howto_css_modals.asp

关于html - 具有悬停效果的图像,当您在 youtube 视频中单击时,应该会在灯箱中弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45448769/

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