<!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) : 图片点击放大
最新推荐文章于 2025-11-05 15:46:08 发布
本文介绍了如何使用HTML、CSS和JavaScript在网页上实现点击按钮后图片的动态放大效果,包括样式设置和JavaScript函数的编写。
970

被折叠的 条评论
为什么被折叠?



