可以用圖片 + 按鍵事件 + Modal 實現
主要邏輯在點選圖片的時候
彈跳出modal
這段使用JSstyle.display='block'
實現開啟效果
當按(X)按鈕的時候隱藏modal,使用style.display = "none"
實現關閉效果
<body>
<h2>IT邦你好</h2>
<button onclick="document.getElementById('modal_id').style.display='block'">
<img src="https://i.imgur.com/WCBS1DF.png" width="420" height="420">
</button>
<div id="modal_id" class="modal">
<form class="modal-content animate" action="https://i.imgur.com/ACmutwk.png">
<div class="imgcontainer">
<span onclick="document.getElementById('modal_id').style.display='none'" class="close" title="Close Modal">×</span>
<img src="https://i.imgur.com/ACmutwk.png" alt="Avatar" class="avatar">
</div>
<div class="container">
<label>
<b>Diplay name</b>
</label>
<input type="text" placeholder="Enter APP Name" name="AppName" required>
<label>
<b>SET PERMISSIONS:</b>
</label>
<button type="submit">Continue</button>
<button >CANCEL</button>
</div>
</form>
</div>
<script>
// 當點圖片的時候顯示modal
var modal = document.getElementById('modal_id');
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
以下是CSS
<style>
/*input格式*/
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
/*按鈕格式*/
button {
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
/*圖片致中*/
.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
position: relative;
}
/* Modal的外觀設定 */
.container {
padding: 16px;
}
span.psw {
float: right;
padding-top: 16px;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
padding-top: 60px;
}
.modal-content {
background-color: #fefefe;
margin: 5% auto 15% auto;
border: 1px solid #888;
width: 80%;
}
/* 關閉按鈕 */
.close {
position: absolute;
right: 25px;
top: 0;
color: #000;
font-size: 35px;
font-weight: bold;
}
/*動畫:點擊圖片慢慢放大*/
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
@-webkit-keyframes animatezoom {
from {
-webkit-transform: scale(0)
}
to {
-webkit-transform: scale(1)
}
}
@keyframes animatezoom {
from {
transform: scale(0)
}
to {
transform: scale(1)
}
}
</style>