Try to search your question here, if you can't find : Ask Any Question Now ?

Javascript Slider Button

HomeCategory: stackoverflowJavascript Slider Button
julie asked 2 weeks ago

I am working on Javascript Image slider. I would like to understand the below code because here the var i= image.length and same var i are taking in for loop command. I am confused on how it works.

<script >

    var slider_content = document.getElementById('box');

    var image = ['a','b', 'c', 'd','e'];

    var i = image.length;


    // function for next slide 

    function nextImage() {
        if (i<image.length) {
            i= i+1;
        } else {
            i = 1;
        }
        slider_content.innerHTML = "<img src="+image[i-1]+".jpg>";
    }


    // function for prew slide

    function prewImage(){

        if (i<image.length+1 && i>1) {
            i= i-1;
        } else {
            i = image.length;
        }
        slider_content.innerHTML = "<img src="+image[i-1]+".jpg>";

    }

1 Answers
Best Answer
Amit answered 2 weeks ago
Your Answer

2 + 19 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com