<! DOCTYPE html >
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 轮播图</ title>
< style>
* {
margin : 0;
padding : 0;
}
.slideshow-container {
width : 500px;
height : 500px;
overflow : hidden;
position : relative;
margin : 0 auto;
background-image : linear-gradient ( to top, #fad0c4 0%, #fad0c4 1%, #ffd1ff 100%) ;
}
.slide {
background-size : cover;
background-repeat : no-repeat;
position : absolute;
opacity : 0;
transition : opacity 0.75s ease-in-out;
top : 50%;
transform : translateY ( -50%) ;
}
.fade {
opacity : 1;
}
.slide img {
width : 100%;
height : 100%;
}
</ style>
</ head>
< body>
< div class = " slideshow-container" >
< div class = " slide fade" >
< img src = " img/1.png" alt = " silde1" >
</ div>
< div class = " slide" >
< img src = " img/2.png" alt = " silde2" >
</ div>
< div class = " slide" >
< img src = " img/3.jpg" alt = " silde3" >
</ div>
</ div>
< script>
var slides = document. querySelectorAll ( '.slide' ) ;
var currentSlide = 0 ;
var slideInterval = setInterval ( nextSlide, 2000 ) ;
function nextSlide ( ) {
slides[ currentSlide] . className = 'slide' ;
currentSlide = ( currentSlide + 1 ) % slides. length;
slides[ currentSlide] . className = 'slide fade' ;
}
</ script>
</ body>
</ html>