gpt4 book ai didi

javascript - 基于同一设计模式的多个内容

转载 作者:行者123 更新时间:2023-11-28 06:15:47 25 4
gpt4 key购买 nike

.modal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
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 */
font-size: 14px;
}
/* Modal Content */

.modal-content {
position: relative;
background-color: black;
color: white;
margin: auto;
padding: 0;
border: 1px solid red;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* Add Animation */

@-webkit-keyframes animatetop {
from {
top: -300px;
opacity: 0
}
to {
top: 0;
opacity: 1
}
}
@keyframes animatetop {
from {
top: -300px;
opacity: 0
}
to {
top: 0;
opacity: 1
}
}
/* The Close Button */

.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: red;
text-decoration: none;
cursor: pointer;
}
.modal-header {
padding: 2px 16px;
background-color: black;
color: white;
}
.modal-body {
padding: 2px 16px;
}
.album {
position: relative;
}
<html>

<head>

<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>


<body>

<div class="album">
<img src="seventhalbum.jpg" alt="First Album" style="width:300;height300;">
<p></p>
<!-- Trigger/Open The Modal -->
<button id="myBtn">Californication</button>

<!-- The Modal -->
<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">X</span>
<h2>Californication</h2>
</div>
<div class="modal-body">
<p>1: Around the World</p>
<p>2: Parallel Universe</p>
<p>3: Scar Tissue</p>
<p>4: Otherside</p>
<p>5: Get on Top</p>
<p>6: Californication</p>
<p>7: Easily</p>
<p>8: Porcelain</p>
<p>9: Emit Remmus</p>
<p>10: I Like Dirt</p>
<p>11: This Velvet Glove</p>
<p>12: Savior</p>
<p>13: Purple Stain</p>
<p>14: Right on Time</p>
<p>15: Road Trippin'</p>
</div>
</div>

</div>
<p></p>
</div>
<div class="album">
<img src="eigthalbum.jpg" alt="First Album" style="width:300;height300;">
<p></p>
<!-- Trigger/Open The Modal -->
<button id="myBtn1">By the Way</button>

<!-- The Modal -->
<div id="myModal1" class="modal">

<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close1">X</span>
<h2>By the Way</h2>
</div>
<div class="modal-body">
<p>1: By the Way</p>
<p>2: Universally Speaking</p>
<p>3: This Is the Place</p>
<p>4: Dosed</p>
<p>5: Don't Forget Me</p>
<p>6: The Zephyr Song</p>
<p>7: Can't Stop</p>
<p>8: I Could Die for You</p>
<p>9: Midnight</p>
<p>10: Through Away Your Television</p>
<p>11: Cabron</p>
<p>12: Tear</p>
<p>13: On Mercury</p>
<p>14: Minor Thing</p>
<p>15: Warm Tape</p>
<p>16: Venice Queen</p>
</div>
</div>

</div>


<script>
// 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 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";
}
}
</script>

<script>
// Get the modal
var modal = document.getElementById('myModal1');

// Get the button that opens the modal
var btn = document.getElementById("myBtn1");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close1")[0];

// When the user clicks 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";
}
}
</script>

</body>

</html>

我试图让我的页面出现多个按钮,这些按钮可以打开不同的模态内容,但使用相同的脚本和 CSS 设计。我有一个问题,它只打开了一个特定的例子。 (顺便说一句,只显示相册)我该如何解决这个问题,将 div 标记为不同不起作用,至少对我来说不起作用。我的代码片段中的两个按钮显示了问题。

最佳答案

更改 javascript 中第二个模态中的 var,使其与另一个不同。

参见 fiddle :https://jsfiddle.net/DIRTY_SMITH/7oe5kh9L/10/

// Get the modal
var modal1 = document.getElementById('myModal1');

// Get the button that opens the modal
var btn1 = document.getElementById("myBtn1");

// Get the <span> element that closes the modal
var span1 = document.getElementsByClassName("close1")[0];

// When the user clicks the button, open the modal
btn1.onclick = function() {
modal1.style.display = "block";
}

// When the user clicks on <span> (X), close the modal
span1.onclick = function() {
modal1.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal1) {
modal1.style.display = "none";
}
}

关于javascript - 基于同一设计模式的多个内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35904679/

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