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;
overflow-x: auto;
gap: 10px;
}
.gallery img {
width: 100px;
height: 100px;
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-img" src="" alt="Enlarged 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-img').attr('src', src);
$('.modal').fadeIn();
});
$('.modal').click(function() {
$(this).fadeOut();
});
});
</script>
</body>
</html>
jquery.touchSwipe
来处理触摸滑动事件。通过以上方法,可以实现一个简单且高效的左右滑动图片聚焦大图效果,并解决常见的技术问题。
没有搜到相关的沙龙