Created
August 19, 2021 15:01
-
-
Save javanigus/ee4d42c7d1a4769636cf15b6a95b2249 to your computer and use it in GitHub Desktop.
Random background image with a fixed background image on a specific page
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
$=jQuery.noConflict(); | |
(function () { | |
var backgrounds = [ | |
"http://d3zntdne6n1qh.cloudfront.net/microsoft-rolling-hills.jpg", | |
"http://d3zntdne6n1qh.cloudfront.net/san-francisco-night.jpg", | |
"http://d3zntdne6n1qh.cloudfront.net/snow-mountain.jpg", | |
"http://d3zntdne6n1qh.cloudfront.net/turqoise-lake.jpg", | |
"http://d3zntdne6n1qh.cloudfront.net/desert.jpg", | |
"http://d3zntdne6n1qh.cloudfront.net/beach.jpg" | |
]; | |
function getRandomInt(max) { | |
return Math.floor(Math.random() * max); | |
} | |
$( document ).ready(function() { | |
var index = getRandomInt(backgrounds.length); | |
if ($("body.page-id-1949").length === 1) { | |
$("body").css('background-image', 'url(http://d3zntdne6n1qh.cloudfront.net/emirates-airlines.jpg)'); | |
} else { | |
$("body").css('background-image', 'url(' + backgrounds[index] + ')'); | |
} | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment