Is there a way to randomize and choose 1 background each time a user clicks on the “open-nav-button”?
I tried to add multiple backgrounds, and then in Custom Code set up a function to pick a random number between 1-5, and set the background to the corresponding image (each number = an image in a ‘const’ ):
<scrip
var menuTrigger = document.getElementById(‘open-menu’);
menuTrigger.onclick = function changeBG {
const area = document.querySelector(‘wireframe-graphic’)
const navBG = [
url(“…1.png”), url(“…2.png”), url(“…3.png”), url(“…4.png”), url(…5.png) (abbreviated)
]
var randNum = Math.floor(Math.random()*5);
area.style.background-image = navBG[randNum];
}
I know the code is wrong, but where does it go wrong?
Hi @Justin_Zhao here is code for your site. You should take care about images as graphic have different position and it may cause problems. If this is intentional do not pay attention to this note.