Javascript 如何在一页上显示多个幻灯片
我在一个HTML页面上设置了两个幻灯片。但它们是相互冲突的 更改一个幻灯片将更改另一个幻灯片。 此外,两个幻灯片中都会出现空白幻灯片 它和使用相同全局索引数组的两个幻灯片有关 有人能帮我修一下密码吗 HTML JavaScriptJavascript 如何在一页上显示多个幻灯片,javascript,slideshow,Javascript,Slideshow,我在一个HTML页面上设置了两个幻灯片。但它们是相互冲突的 更改一个幻灯片将更改另一个幻灯片。 此外,两个幻灯片中都会出现空白幻灯片 它和使用相同全局索引数组的两个幻灯片有关 有人能帮我修一下密码吗 HTML JavaScript var slideIndex = 0; showSlides(); var slides,dots; function showSlides() { var i; slides = document.getElementsByClassName(
var slideIndex = 0;
showSlides();
var slides,dots;
function showSlides() {
var i;
slides = document.getElementsByClassName("mySlides");
dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex> slides.length) {slideIndex = 1}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
setTimeout(showSlides, 8000); // Change image every 8 seconds
}
function plusSlides(position) {
slideIndex +=position;
if (slideIndex> slides.length) {slideIndex = 1}
else if(slideIndex<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[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
function currentSlide(index) {
if (index> slides.length) {index = 1}
else if(index<1){index = 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[index-1].style.display = "block";
dots[index-1].className += " active";
}
var slideIndex=0;
放映幻灯片();
var玻片、圆点;
函数showSlides(){
var i;
幻灯片=document.getElementsByClassName(“mySlides”);
dots=document.getElementsByClassName(“dot”);
对于(i=0;islides.length){slideIndex=1}
对于(i=0;islides.length){slideIndex=1}
else if(slideIndex slides.length){index=1}
else if(索引
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
.slideshow1 {
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 75vh;
width: 100%;
position: relative;
}
.slideshow1 .color_layer {
background-color: rgba(0,0,0,0.5);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.slideshow1 .wrapper {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 800px;
text-align: center;
}
.slideshow1 .text1 {
font-weight: bold;
color: white;
}
.slideshow1 .text2 {
font-weight: 200;
color: white;
}
.slideshow_dots {
position: absolute;
bottom: 10%;
left: 50%;
transform: translate(-50%, -50%);
color: #717171;
}
/* Slideshow */
.slideshow1 .mySlides {
display: none;
height: 75vh;
}
.slideshow1 .mySlides img {
height: 100%;
object-fit: cover;
}
.slideshow1 .slideshow-container {
position: absolute;
left: 0;
top: 0;
right: 100%;
bottom: 100%;
width: 100%;
}
/* Next & previous buttons */
.slideshow1 .prev, .slideshow1 .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -22px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
background-color: dodgerblue;
}
/* Position the "next button" to the right */
.slideshow1 .next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.slideshow1 .prev:hover, .slideshow1 .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* The dots/bullets/indicators */
.slideshow1 .dot {
cursor: pointer;
font-size: 12px;
margin: 0 5px;
color: #717171;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.slideshow1 .active, .slideshow1 .dot:hover {
color: #bbb;
}
/* Fading animation */
.slideshow1 .fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 2s;
animation-name: fade;
animation-duration: 2s;
}
@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.text {font-size: 11px}
}
.slideshow2 {
width: 100%;
height: 500px;
margin: 30px 0;
position: relative;
}
.slideshow2 .img {
width: 50%;
height: 500px;
float: left;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
position: relative;
}
.slideshow2 .subdiv {
width: 50%;
height: 500px;
float: left;
padding: 10px 5% 10px 2%;
display: table;
box-shadow: outset -200px 0 110px 0 #000000;
}
.slideshow2 .subdiv .wrapper {
display: table-cell;
vertical-align: middle;
}
.slideshow2 .subdiv .wrapper #quote {
color: #2b2b2b;
line-height: 30px;
margin-top: 25px;
font-size: 20px;
letter-spacing: 1.5px;
}
.slideshow2 .subdiv .wrapper #quoter {
color: #747474;
margin-top: 25px;
font-size: 20px;
}
/*Slideshow*/
.slideshow2 .slideshow-container {
height: 100%;
width: 100%;
}
.slideshow2 .slide-1 {
}
.slideshow2 .slide-1 .img {
background-image: linear-gradient(to right, rgba(255,255,255,0) 50%,rgba(255,255,255,1) 100%), url(https://cdn.pixabay.com/photo/2014/12/15/17/16/pier-569314__180.jpg);
}
.slideshow2 .slide-2 {
}
.slideshow2 .slide-2 .img {
background-image: linear-gradient(to right, rgba(255,255,255,0) 50%,rgba(255,255,255,1) 100%), url(https://cdn.pixabay.com/photo/2016/04/15/04/02/water-1330252__180.jpg);
}
.slideshow2 .slide-3 {
}
.slideshow2 .slide-3 .img {
background-image: linear-gradient(to right, rgba(255,255,255,0) 50%,rgba(255,255,255,1) 100%), url(https://cdn.pixabay.com/photo/2016/03/04/19/36/beach-1236581__180.jpg);
}
/* Next & previous buttons */
.slideshow2 .prev, .slideshow2 .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -22px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
background-color: dodgerblue;
}
/* Position the "next button" to the right */
.slideshow2 .next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.slideshow2 .prev:hover, .slideshow2.next:hover {
background-color: rgba(0,0,0,0.8);
}
var slideIndex = 0;
showSlides();
var slides,dots;
function showSlides() {
var i;
slides = document.getElementsByClassName("mySlides");
dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex> slides.length) {slideIndex = 1}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
setTimeout(showSlides, 8000); // Change image every 8 seconds
}
function plusSlides(position) {
slideIndex +=position;
if (slideIndex> slides.length) {slideIndex = 1}
else if(slideIndex<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[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
function currentSlide(index) {
if (index> slides.length) {index = 1}
else if(index<1){index = 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[index-1].style.display = "block";
dots[index-1].className += " active";
}