Answer the question
In order to leave comments, you need to log in
How to make a random website background with css connection?
I found a connection for outputting a random background to the site: goo.gl/55e7Ex , on the site the background is located on top of the site, then it is filled with color, as on https://goo.gl/6E1rbu. So, I want to make a random output of the background with its accompanying color, i.e. for each image its own color. Any ideas how to implement this?
Answer the question
In order to leave comments, you need to log in
<script>
var backgrounds = [
"#f00 url(images/backgrounds/img1.jpg) top center",
"#0f0 url(images/backgrounds/img2.jpg) top center",
"#00f url(images/backgrounds/img3.jpg) top center"
];
document.body.style.background = backgrounds[Math.floor(Math.random() * (backgrounds.length + 1))];
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question