Skip to content

Instantly share code, notes, and snippets.

@andrewrs
Created March 11, 2019 19:56
Show Gist options
  • Save andrewrs/8b03778ab79dd4e264f8a61bbb248208 to your computer and use it in GitHub Desktop.
Save andrewrs/8b03778ab79dd4e264f8a61bbb248208 to your computer and use it in GitHub Desktop.
js image/description rotation
var theImages = new Array()
theImages[0] = "/path_to/1.jpg"
theImages[1] = "/path_to/2.jpg"
theImages[2] = "/path_to/3.jpg"
theImages[3] = "/path_to/4.jpg"
var theText = new Array()
theText[0] = "Image 1 description"
theText[1] = "Image 2 description"
theText[2] = "Image 3 description"
theText[3] = "Image 4 description"
var j = 0
var p = theImages.length;
if (window.innerWidth > 1000) {
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.getElementById("abouttext").innerHTML = theText[whichImage];
document.getElementById('imgbk').style.backgroundImage="url('"+theImages[whichImage]+"')";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment