W3 Schools图片幻灯片订单反转

时间:2016-12-18 14:35:10

标签: javascript css3

我已经实现了w3学校http://www.w3schools.com/w3css/w3css_slideshow.asp所示的幻灯片显示,但我对其“滑动”的顺序存在问题。我将自动幻灯片放映与幻灯片放映指示器结合在一起,但是当我加载页面时,订单是3,2,1。因此指示器从右向左移动。我自己也没有兴趣,所以希望有人可以帮助我。

<div class="imageContent">
                    <div class="w3-content w3-display-container" style="max-width:670px">
                    <a href="mypage.php"><img class="mySlides" src="img/image1.jpg" style="width:100%"></a>
                    <a href="mypage.php"><img class="mySlides" src="img/image2.jpg" style="width:100%"></a>
                    <a href="mypage.php"><img class="mySlides" src="img/image3.jpg" style="width:100%"></a>
                    <div class="w3-center w3-section w3-large w3-text-white w3-display-bottommiddle" style="width:100%">
                    <div class="w3-left w3-padding-left w3-hover-text-khaki" onclick="plusDivs(-1)">&#10094;</div>
                    <div class="w3-right w3-padding-right w3-hover-text-khaki" onclick="plusDivs(1)">&#10095;</div>
                    <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(1)"></span>
                    <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(2)"></span>
                    <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(3)"></span>
                </div>
            </div>

            <script>
                var slideIndex = 1;

                showDivs(slideIndex);

                function plusDivs(n) {
                    showDivs(slideIndex += n);
                }

                function currentDiv(n) {
                    showDivs(slideIndex = n);
                }

                function showDivs(n) {
                    var i;

                    var x = document.getElementsByClassName("mySlides");
                    var dots = document.getElementsByClassName("demo");
                    if (n > x.length) {slideIndex = 1}    
                    if (n < 1) {slideIndex = x.length}
                    for (i = 0; i < x.length; i++) {
                        x[i].style.display = "none";  
                    }
                    for (i = 0; i < dots.length; i++) {
                        dots[i].className = dots[i].className.replace(" w3-white", "");
                    }
                    x[slideIndex-1].style.display = "block";  
                    dots[slideIndex-1].className += " w3-white";

                }

                carousel();

                function carousel() {

                var i;
                var x = document.getElementsByClassName("mySlides");
                for (i = 0; i < x.length; i++) {
                    x[i].style.display = "none"; 
                }
                slideIndex++;
                if (slideIndex > x.length) {slideIndex = 1} 
                x[slideIndex-1].style.display = "block"; 
                setTimeout(carousel, 5000); // Change image every 5 seconds
                plusDivs(1);
                }
                </script>

            </div>

1 个答案:

答案 0 :(得分:0)

我需要用showDivs(slideIndex)替换plusDivs(1)

if (date.getValue() == null) {
    // Here --------^