L
L
Lenwoot2015-10-16 10:45:53
css
Lenwoot, 2015-10-16 10:45:53

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

2 answer(s)
S
Sergei Melnikov, 2015-10-16
@powepmakerru

<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>

I
IceJOKER, 2015-10-16
@IceJOKER

class="first_background"
class="second_background"
class="third_background"

etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question