Last active
August 31, 2017 10:54
-
-
Save ihorduchenko/c80386aff43a73581ab5e23c1528386d to your computer and use it in GitHub Desktop.
Gets random image from image set
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
<div class="randomImageSet hidden"> | |
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('contact_page_banner_widget')) : else : ?><?php endif; ?> | |
</div> | |
<div id="randomImage" class="relative top-bk"></div> |
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
const imgArray = []; | |
(function slidesArray() { | |
$(".randomImageSet img").each(function() { | |
var arrayItem = { image: $(this).attr('src')}; | |
imgArray.push(arrayItem); | |
}); | |
return imgArray; | |
}()); | |
var randomArray = imgArray; | |
(function choosePic() { | |
var randomNum = Math.floor(Math.random() * randomArray.length); | |
var img = randomArray[randomNum].image; | |
var random = document.getElementById("randomImage"); | |
random.style.backgroundImage = 'url(' + img + ')'; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment