Streaming live at 10am (PST)

Randomly generate background GIFs

Hello,
So, in the long run I want to be able to randomly generate different background videos upon refresh. I am of the understanding Weblog doesn’t have that function yet. In the meantime is there a way to randomly generate background GIFs?

Thanks in advance for the help!

If you can setup at least two layers of backgrounds and post your published link here, I can help you with the code.

Cool.
Can you be a bit more specific as to what you need from me? I’m a novice at this stuff.
Thanks for the help!

Make a container to hold the backgrounds.

Make at least two divs with backgrounds as shown.

Instead of jpg, you can use gif.

1 Like

Cool.
Is there a way to make it so a different GIF is randomly generated upon refresh?

Once you have done that, paste this in Page Settings > Custom Code > Footer Code:

<script>
var Webflow = Webflow || [];
Webflow.push(function() {
  var bg = $('.background-wrap').children();
  bg.eq( Math.floor(Math.random() * bg.length) ).show().siblings().remove();
});
</script>
2 Likes

This worked great. Thanks.
Why couldn’t you do the same thing with video? It seems like you could, no?

Yes, why not? The setup is the same.

but remember. whenever you put a background video, all videos will load. so your load time could be longer.

They will start streaming, but it will almost immediately stop as the script will remove the element from the page.