我需要一个DW网页插入滑动图片代码
时间: 2024-03-05 11:51:13 浏览: 145
你可以使用以下代码实现网页插入滑动图片的效果:
```html
<!DOCTYPE html>
<html>
<head>
<title>Slideshow</title>
<style type="text/css">
#slideshow {
position: relative;
height: 300px;
overflow: hidden;
}
#slideshow img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
max-height: 100%;
max-width: 100%;
opacity: 0;
transition: opacity 1s ease-in-out;
}
#slideshow img.active {
opacity: 1;
}
#slideshow img.previous {
opacity: 0;
z-index: -1;
}
#slideshow img.next {
opacity: 0;
z-index: 1;
}
</style>
</head>
<body>
<div id="slideshow">
<img src="image1.jpg" class="active" />
<img src="image2.jpg" class="next" />
<img src="image3.jpg" class="previous" />
</div>
<script type="text/javascript">
var images = document.querySelectorAll('#slideshow img');
var current = 0;
function slide() {
images[current].classList.remove('active');
images[current].classList.add('previous');
current = (current + 1) % images.length;
images[current].classList.remove('next');
images[current].classList.add('active');
setTimeout(slide, 5000);
}
setTimeout(slide, 5000);
</script>
</body>
</html>
```
将上述代码保存为一个html文件,然后将需要显示的图片放置在同一目录下,以文件名image1.jpg、image2.jpg、image3.jpg等命名,即可实现网页插入滑动图片的效果。
阅读全文