jQuery 弹出层相册是一种基于 jQuery 库的网页交互功能,用于在网页上展示图片集合,并允许用户通过点击图片来查看大图。这种相册通常包含缩略图和大图的切换功能,有时还支持左右滑动切换图片。
以下是一个简单的 jQuery 弹出层相册示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery 弹出层相册</title>
<style>
.gallery img {
width: 100px;
height: 100px;
margin: 5px;
cursor: pointer;
}
.lightbox {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
justify-content: center;
align-items: center;
}
.lightbox img {
max-width: 90%;
max-height: 90%;
}
</style>
</head>
<body>
<div class="gallery">
<img src="image1.jpg" alt="Image 1">
<img src="image2.jpg" alt="Image 2">
<img src="image3.jpg" alt="Image 3">
</div>
<div class="lightbox">
<img src="" alt="" id="lightbox-image">
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('.gallery img').click(function() {
var src = $(this).attr('src');
$('#lightbox-image').attr('src', src);
$('.lightbox').fadeIn();
});
$('.lightbox').click(function() {
$(this).fadeOut();
});
});
</script>
</body>
</html>
通过以上方法,可以有效地解决 jQuery 弹出层相册中常见的问题。
领取专属 10元无门槛券
手把手带您无忧上云