Created
March 11, 2019 19:56
-
-
Save andrewrs/8b03778ab79dd4e264f8a61bbb248208 to your computer and use it in GitHub Desktop.
js image/description rotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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