CSS / JS图像幻灯片无法在小屏幕上正确显示,并且自动滚动不起作用

时间:2019-05-29 23:49:47

标签: html css slideshow

我已经有点工作了,但是对于我的任务,CSS交互必须能够正常工作。这只是其中之一。到目前为止,我的导航栏运行良好。

我已经尝试了Frankensteining幻灯片中的不同代码,但这无济于事或变得更糟(压缩的图像和按钮)

#slide{
    width:96%;
    }

* {
    box-sizing: border-box
}

.mySlides {
    display: none
}

.slideshow-container {
    width: 100%;
    position: relative;
    margin: -10px;

}
/* Next & previous buttons */
.prev, .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;
}
/* Position the "next button" to the right */
.next {
    right: 0;
    border-radius: 3px 0 0 3px;
}


/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
    background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
    color: #f2f2f2;
    font-size: 15px;
    padding: 8px 12px;
    position: absolute;
    bottom: 8px;
    width: 100%;
    text-align: center;
}

/* The dots/bullets/indicators */
.dot {
    cursor: pointer;
    height: 13px;
    width: 13px;
    margin: 0 2px;
    background-color: #bbb;
    border-radius: 50%;
    display: inline-block;
    transition: background-color 0.6s ease;
}
.active, .dot:hover {
    background-color: #717171;
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
  .text {font-size: 11px}
}
/*This is the code for a automatic scrolling image gallery, taken from stackoverflow and edited to have more than 4 images and move every 5 seconds */
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, 5000); // Change image every 5 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";
}
<div id="slide">
  <div class="slideshow-container">
    <div class="mySlides fade"> <a href="images/pic1.jpg"><img src="images/pic1.jpg" height="65%" ></a> </div>
    <div class="mySlides fade"> <a href="images/pic2.jpg"><img src="images/pic2.jpg" height="65%" ></a> </div>
    <div class="mySlides fade"> <a href="images/pic3.jpg"><img src="images/pic3.jpg" height="65%" ></a> </div>
    <div class="mySlides fade"> <a href="images/pic4.jpg"><img src="images/pic4.jpg" height="65%" ></a> </div>
    <div class="mySlides fade"> <a href="images/pic5.jpg"><img src="images/pic5.jpg" height="65%" ></a> </div>
    <div class="mySlides fade"> <a href="images/pic6.jpg"><img src="images/pic6.jpg" height="65%" ></a> </div>
    <a class="prev" onclick="plusSlides(-1)">&#10094;</a> <a class="next" onclick="plusSlides(1)">&#10095;</a> </div>
  <br>
  <div style="text-align:center"> 
  <span class="dot" onclick="currentSlide(1)"></span> 
  <span class="dot" onclick="currentSlide(2)"></span> 
  <span class="dot" onclick="currentSlide(3)"></span>
  <span class="dot" onclick="currentSlide(4)"></span>
  <span class="dot" onclick="currentSlide(5)"></span>
  <span class="dot" onclick="currentSlide(5)"></span>
  </div>
   </div>

https://pasteboard.co/Ih0M6hO.png现在的样子。 https://pasteboard.co/Ih0LPzk.png它的外观。

0 个答案:

没有答案