array of images javascript
JavaScript
var imgArray = new Array();
imgArray[0] = new Image();
imgArray[0].src = 'images/anakin_starfighter.png';
imgArray[1] = new Image();
imgArray[1].src = 'images/obi_wan_starfighter.png';
imgArray[2] = new Image();
imgArray[2].src = 'images/naboo_starfighter.png';
imgArray[3] = new Image();
imgArray[3].src = 'images/darthvader.png';
imgArray[4] = new Image();
imgArray[4].src = 'images/x_wing.png';
// let robot1 = new Sprite(imgArray[0].src,window.document.getElementById("playground"),new Position(250,250),"robot")
let avion11 = new Sprite(imgArray[0].src,window.document.getElementById("playground"),new Position(75,0),"avion11")
let avion22 = new Sprite(imgArray[1].src,window.document.getElementById("playground"),new Position(550,150),"avion22")
let avion33 = new Sprite(imgArray[2].src,window.document.getElementById("playground"),new Position(0,150),"avion33")
let avion44 = new Sprite(imgArray[4].src,window.document.getElementById("playground"),new Position(550,350),"avion44")
let darthvader = new Sprite(imgArray[3].src,window.document.getElementById("playground"),new Position(150,75),"darthvader")
let
const recPosition = function() {
return{x:parseInt(this.style.left), y:parseInt(this.style.top)};
}
alert(imgArray[1].recPosition().x)
const aqua=document.getElementById("playground");
const Move=function(){
const Move=function(){
for(let i=0;i<imgArray.length;i++){
let div = document.getElementsByTagName("img")[i].getAttribute("id");
let photo = document.getElementById(div)
let rect = photo.getBoundingClientRect();
if(imgArray[i].x+50>=aqua.width){
imgArray[i].rect.left=-1;
}
else if(imgArray[i].x<=0){
imgArray[i].rect.left=1;
}
imgArray[i].style.left+=imgArray[i].rect.left;
if(imgArray[i].y+50>=aqua.height){
imgArray[i].rect.top=-1;
}
else if(imgArray[i].y<=0){
imgArray[i].rect.top=1;
}
imgArray[i].style.top+=imgArray[i].rect.top ;
}
}
}
const Animate=function(){
Move()
setTimeout(Animate,10);
}
// Animate();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;
}
}
}
Also in JavaScript:
- Title
- $.ajax javascript
- Category
- JavaScript
- Title
- create array with specific size javascript
- Category
- JavaScript
- Title
- check row empty array javascript
- Category
- JavaScript
- Title
- call javascript function from html
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- how to import npm packages in node.js?
- Category
- JavaScript
- Title
- how to pass props in react test cases
- Category
- JavaScript
- Title
- chrome extension get current tab from popup
- Category
- JavaScript
- Title
- express get params after ?
- Category
- JavaScript
- Title
- fs create or edit file
- Category
- JavaScript
- Title
- change node version
- Category
- JavaScript
- Title
- form taglib in jsp
- Category
- JavaScript
- Title
- how to remove link in image in jquery
- Category
- JavaScript
- Title
- how to find id in array javascript
- Category
- JavaScript
- Title
- inner html jquery
- Category
- JavaScript
- Title
- javascript check if string contains substring
- Category
- JavaScript
- Title
- get width of a dom element js
- Category
- JavaScript
- Title
- how to add element in json object
- Category
- JavaScript
- Title
- append rotated triangle in anchor tag
- Category
- JavaScript
- Title
- how to include local image files in javascript object
- Category
- JavaScript
- Title
- how to clear radio field in jquery
- Category
- JavaScript
- Title
- array.filter in javascript not working in w3schools
- Category
- JavaScript
- Title
- interaction js drag anddrop
- Category
- JavaScript
- Title
- how to use the foreach method in javascript
- Category
- JavaScript
- Title
- how to link javascript to html
- Category
- JavaScript
- Title
- all fields entered jquery enable submit button
- Category
- JavaScript
- Title
- angular material table
- Category
- JavaScript
- Title
- Javascript clear canvas
- Category
- JavaScript
- Title
- input not detecting text
- Category
- JavaScript
- Title
- how to freeze js object
- Category
- JavaScript
- Title
- event handler attachment jquery
- Category
- JavaScript
- Title
- javascript button onclick
- Category
- JavaScript
- Title
- add webpack to react project
- Category
- JavaScript
- Title
- how to run different node app on server different domains
- Category
- JavaScript
- Title
- discord.js
- Category
- JavaScript
- Title
- dynamic for loop react
- Category
- JavaScript
- Title
- javascript anagram check
- Category
- JavaScript
- Title
- filter table search
- Category
- JavaScript
- Title
- how to compare two strings in javascript if condition
- Category
- JavaScript
- Title
- if checkbox checked jquery value 1
- Category
- JavaScript
- Title
- how to animate array oy react elements
- Category
- JavaScript
- Title
- detect browser javascript
- Category
- JavaScript
- Title
- change p tag text javascript
- Category
- JavaScript
- Title
- how to run function after animation complete jquery
- Category
- JavaScript
- Title
- ajax .put
- Category
- JavaScript
- Title
- hasownproperty.call
- Category
- JavaScript
- Title
- how to assign same value of a key to 2 different keys in output JSON jolt
- Category
- JavaScript
- Title
- how to turn decimales into percents with javascript
- Category
- JavaScript
- Title
- how to use json stringify in javascript
- Category
- JavaScript
- Title
- angular ngclass
- Category
- JavaScript
- Title
- change width in js
- Category
- JavaScript
- Title
- express validator always return error
- Category
- JavaScript
- Title
- difference between e.preventdefault and e.stoppropagation and return false
- Category
- JavaScript
- Title
- find leap year javascript
- Category
- JavaScript
- Title
- angular material theme colors
- Category
- JavaScript
- Title
- How to pass a map from controller to javascript function in VF page
- Category
- JavaScript
- Title
- angular npm angular material
- Category
- JavaScript
- Title
- how to reload vscode
- Category
- JavaScript
- Title
- Alert.alert closing expo
- Category
- JavaScript
- Title
- add element to array javascript
- Category
- JavaScript
- Title
- how to get variable in local storage in javascript
- Category
- JavaScript
- Title
- javascript click button by id
- Category
- JavaScript
- Title
- dropzone add download button addedfile
- Category
- JavaScript
- Title
- javascript array remove duplicates
- Category
- JavaScript
- Title
- how to know which button clicked in javascript
- Category
- JavaScript
- Title
- ${ js
- Category
- JavaScript
- Title
- group by in javascript
- Category
- JavaScript
- Title
- get the current url javascript
- Category
- JavaScript
- Title
- how to clone an object in javascript
- Category
- JavaScript
- Title
- how to update all node libraries
- Category
- JavaScript
- Title
- busca binária em javascript
- Category
- JavaScript
- Title
- float to currency
- Category
- JavaScript
- Title
- adding delay in javascript foreach loop
- Category
- JavaScript
- Title
- hoisting in javascript
- Category
- JavaScript
- Title
- javascript add commas to number
- Category
- JavaScript
- Title
- area of a circle
- Category
- JavaScript
- Title
- How to get the path to the file that required your module?
- Category
- JavaScript
- Title
- axios post with header
- Category
- JavaScript
- Title
- javascript array stackoverflow
- Category
- JavaScript
- Title
- javascript add text to textarea overwrite
- Category
- JavaScript
- Title
- how to make a factorial function in javascript
- Category
- JavaScript
- Title
- how to attach javascript to html
- Category
- JavaScript
- Title
- if clicked outside of div jquery
- Category
- JavaScript
- Title
- document delete element
- Category
- JavaScript
- Title
- how to make a random number guessing game in javascript
- Category
- JavaScript
- Title
- how to find the index of a value in an array in javascript
- Category
- JavaScript
- Title
- how to add class to element on mouseclick with js
- Category
- JavaScript
- Title
- elseif javascript
- Category
- JavaScript
- Title
- how to name a javascript variable
- Category
- JavaScript
- Title
- html to json
- Category
- JavaScript
- Title
- es6 closures
- Category
- JavaScript
- Title
- angular onchange event
- Category
- JavaScript
- Title
- how to check if something is array javascript
- Category
- JavaScript
- Title
- initialize array javascript
- Category
- JavaScript
- Title
- how to open a new html page on button click in javascript
- Category
- JavaScript
- Title
- add jquery to wordpress
- Category
- JavaScript
- Title
- email regex
- Category
- JavaScript
- Title
- how to make a deep copy in javascript
- Category
- JavaScript
- Title
- checked unchecked through js
- Category
- JavaScript
- Title
- expo open app settings
- Category
- JavaScript