rootKID Posted January 30, 2021 Share Posted January 30, 2021 Hi W3S! Been a while (as always). So i am in need of support yet again. I have this fun project of mine, where i have 2 background images i really wonna show, but at random on each page load... so as the title says, is there a way to do this with simple javascript? As said i have 2 background images i wanna show and since im not the best with javascript, i kinda hoped i could get you guys to show me an example or at least guide me to where i could look? I have looked at W3Schools main website but not sure if i'm looking in the right spot. Many thanks in advance! :D PS: The idea behind the background images is that they should be attached to the "<body>" tag for kinda "overlayers". If that makes sence? I already have a "black" background, and these images are supposed to look like "x"s... but in different colors... hense the random images... Anyways as always, thanks in advance and i hope you guys can help me... again... as always... Happy new year so far, and hope all are with good health! And watch out! <3 Regards, rootKID :D Link to comment Share on other sites More sharing options...
dsonesuk Posted January 30, 2021 Share Posted January 30, 2021 Use random script to produce number 0 to 1, https://www.w3schools.com/js/js_random.asp if 0 add a class to body tag example 'bg0', if 1 then use 'bg1' then use css to apply background depending on class name used. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now