jQuery 是一个快速、小巧且功能丰富的 JavaScript 库,它简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。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 {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.gallery img {
width: 200px;
height: 200px;
object-fit: cover;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</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>
<script>
$(document).ready(function() {
$('.gallery img').click(function() {
var src = $(this).attr('src');
$('#modal').html('<img src="' + src + '" alt="Enlarged Image">').show();
});
$(document).on('click', '#modal', function() {
$(this).hide();
});
});
</script>
</body>
</html>通过以上方法,可以有效解决 jQuery 相册中常见的问题,提升用户体验。
没有搜到相关的文章