Thursday, August 3, 2017

DOM and javascript photo slider simple

css

.slideshow-container {
        position: relative;
        width: 100%;
        height: 500px;
        overflow: hidden;
        .slides {
            display: block;
            //position: absolute;
            margin: 0 auto;
            width: 1600px;
            height: 500px;
            visibility: hidden;
            opacity: 0;
            img {
                display: block;
                width: 1600px;
                height: 500px;
            }
            /* Fading animation */
            &.fadein {
                visibility: visible;
                opacity: 1;
                @include animation(slider-links-fadein 1s ease-out);
            }
        }
        /* Next & previous buttons */
        .prev, .next {
            cursor: pointer;
            position: absolute;
            top: 50%;
            width: auto;
            margin-top: -22px;
            padding: 16px;
            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 {
        padding: 15px;
        position: absolute;
        left: 0;
        top: 0;
        background-color: rgba(0,0,0,0.5);
        color: #f2f2f2;
        font-size: 19px;
        width: 400px;
        height: 100%;
        margin-left: 60%;
    }

    /* 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, &:hover {
            background-color: #717171;
        }
    }



script


<script>
        var slideIndex = 0;
        function plusSlides(n) {
            showSlides(slideIndex += n);
        }
        function currentSlide(n) {
            showSlides(slideIndex = n);
        }
        function showSlides(n) {
            var i;
            var slides = document.getElementsByClassName("slides");
            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].className = "anim9s slides";
            }
            for (i = 0; i < dots.length; i++) {
                dots[i].className = dots[i].className.replace(" active", "");
            }
            slides[slideIndex - 1].className = "anim9s slides fadein";
            dots[slideIndex - 1].className += " active";
        }
        var autoSlides = function () {
            var i;
            var slides = document.getElementsByClassName("slides");
            for (i = 0; i < slides.length; i++) {
                slides[i].className = "anim9s slides";
            }
            slideIndex++;
            if (slideIndex > slides.length) {
                slideIndex = 1;
            }
            slides[slideIndex - 1].className = "anim9s slides fadein";
            setTimeout(autoSlides, 5000); // Change image every 2 seconds
        };
        autoSlides();
    </script>