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>
#slideshow {
position: relative;
width: 600px;
height: 400px;
overflow: hidden;
}
#slideshow img {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity 1s ease-in-out;
}
</style>
</head>
<body>
<div id="slideshow">
<img src="image1.jpg" alt="Image 1">
<img src="image2.jpg" alt="Image 2">
<img src="image3.jpg" alt="Image 3">
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
var images = $('#slideshow img');
var index = 0;
function showImage(index) {
images.hide();
images.eq(index).show();
}
function nextImage() {
index = (index + 1) % images.length;
showImage(index);
}
images.eq(0).show();
setInterval(nextImage, 3000); // 每 3 秒切换一次图片
});
</script>
</body>
</html>
通过以上内容,你应该对 jQuery 图片幻灯有了全面的了解,并能解决一些常见问题。
领取专属 10元无门槛券
手把手带您无忧上云