您所在的位置:首页 - 生活 - 正文生活
js实现幻灯片效果
镳嫡 05-14 【生活】 133人已围观
摘要```htmlCreatingJavaScriptSlideshow/*Stylesforslideshow*/.slideshow-container{max-width:1000px;positi
```html
/* Styles for slideshow */
.slideshowcontainer {
maxwidth: 1000px;
position: relative;
margin: auto;
}
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margintop: 22px;
color: white;
fontweight: bold;
fontsize: 18px;
transition: 0.6s ease;
borderradius: 0 3px 3px 0;
}
/* Position the "next button" to the right */
.next {
right: 0;
borderradius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit seethrough */
.prev:hover, .next:hover {
backgroundcolor: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: f2f2f2;
fontsize: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
textalign: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: f2f2f2;
fontsize: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
backgroundcolor: bbb;
borderradius: 50%;
display: inlineblock;
transition: backgroundcolor 0.6s ease;
}
.active, .dot:hover {
backgroundcolor: 717171;
}
/* Fading animation */
.fade {
webkitanimationname: fade;
webkitanimationduration: 1.5s;
animationname: fade;
animationduration: 1.5s;
}
@webkitkeyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex = n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i ) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i ) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex1].style.display = "block";
dots[slideIndex1].className = " active";
}