Jump to content

Changing image on refresh

Recommended Posts


I'm hoping to replicate this effect: https://bddw.com/ where the image element changes every time the page is reloaded. I've found some code samples for 7.0 and similarly older versions but having issues with implementation. 

This is the code I am working with now: 


   var images = [

   var imgCount = images.length;

   var randNumber=Math.floor((Math.random() * imgCount) + 1);

   imgURL = "url('" + images[randNumber-1] + "')";

   var body=document.getElementById('collection-542ba4a1e4b032a0dde82b31');
   body.style.backgroundSize="100% auto";

However, it doesn't seem to be doing anything. 

I think part of the issue is the image sources are incorrect. How do I adequately find the image url from the asset library? 

Thank you!!

Link to comment
  • Replies 3
  • Views 352
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.