Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

array of images javascript

var imgArray = new Array();

imgArray[0] = new Image();
imgArray[0].src = 'images/img/Splash_image1.jpg';

imgArray[1] = new Image();
imgArray[1].src = 'images/img/Splash_image2.jpg';

/* ... more images ... */

imgArray[5] = new Image();
imgArray[5].src = 'images/img/Splash_image6.jpg';

/*------------------------------------*/

function nextImage(element)
{
    var img = document.getElementById(element);

    for(var i = 0; i < imgArray.length;i++)
    {
        if(imgArray[i].src == img.src) // << check this
        {
            if(i === imgArray.length){
                document.getElementById(element).src = imgArray[0].src;
                break;
            }
            document.getElementById(element).src = imgArray[i+1].src;
            break;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: sequelize migration add column 
Javascript :: link to another page and achor react 
Javascript :: call button click event in javascript 
Javascript :: sort arrays according to first array js 
Javascript :: react click outside 
Javascript :: moment.add 
Javascript :: how to unselect input javascript 
Javascript :: polyfill of bind 
Javascript :: how to make dynamic title for screen in react native 
Javascript :: regex usage 
Javascript :: create a loop that runs through each item in an array 
Javascript :: how to make a random if else in js 
Javascript :: js typeof number 
Javascript :: convert arrow function to normal function javascript 
Javascript :: push json into json 
Javascript :: check if all values in array are negative javascript 
Javascript :: sample docker for node js 
Javascript :: bin2hex in js 
Javascript :: javascript 2 return values 
Javascript :: read json using fs 
Javascript :: hide column in antd table using js / react with conditional rendering 
Javascript :: disable button using jquery 
Javascript :: safeAreaProvider 
Javascript :: base64 encoded data to object in javascript 
Javascript :: js foreach method 
Javascript :: Auto open browser when run dev nextjs 
Javascript :: how to use saved image on react 
Javascript :: read url param data in javascript 
Javascript :: vue mounted refresh page once 
Javascript :: react bootstrap font awesome icons 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =