<!DOCTYPE html>
<html>
<head>
<style>
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: none;
justify-content: center;
align-items: center;
z-index: 9999;
}
.overlay img {
max-width: 90%;
max-height: 90%;
cursor: pointer;
}
</style>
</head>
<body>
<button onclick="enlargeImage('http://111.jpg')">放大</button>
<div class="overlay" onclick="closeOverlay()">
<img id="enlargedImg" src="">
</div>
<script>
function enlargeImage(img) {
var overlay = document.querySelector(".overlay");
var enlargedImg = document.getElementById("enlargedImg");
enlargedImg.src = img;
overlay.style.display = "flex";
}
function closeOverlay() {
var overlay = document.querySelector(".overlay");
overlay.style.display = "none";
}
</script>
</body>
</html>
前端技术(14) : 图片点击放大
最新推荐文章于 2024-06-11 10:19:16 发布