Skip to content

Instantly share code, notes, and snippets.

@javanigus
Created August 19, 2021 15:01
Show Gist options
  • Save javanigus/ee4d42c7d1a4769636cf15b6a95b2249 to your computer and use it in GitHub Desktop.
Save javanigus/ee4d42c7d1a4769636cf15b6a95b2249 to your computer and use it in GitHub Desktop.
Random background image with a fixed background image on a specific page
$=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