jQuery相册画廊(Gallery)是一种基于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 {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.gallery img {
width: 100px;
height: 100px;
object-fit: cover;
cursor: pointer;
}
.modal {
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;
}
.modal 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="modal">
<img id="modal-image" src="" alt="Modal 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');
$('#modal-image').attr('src', src);
$('.modal').fadeIn();
});
$('.modal').click(function() {
$(this).fadeOut();
});
});
</script>
</body>
</html>
通过以上方法,可以有效解决jQuery相册画廊中常见的问题,提升用户体验。
领取专属 10元无门槛券
手把手带您无忧上云