Created
August 17, 2016 20:02
-
-
Save ackernaut/27c9778ec6cc7ca8a5d1b6c17b794bcd to your computer and use it in GitHub Desktop.
Get random image from unsplash
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
// Requires jQuery or Zepto | |
// Get Random Image (unsplash.it) | |
var jsRandomImg = $('.js-random-img'); | |
function getRandomIntInclusive(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
jsRandomImg.each(function () { | |
var imageNumber = getRandomIntInclusive(0, 1084); | |
$(this).prop('src', 'https://unsplash.it/640/360?image=' + imageNumber); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment