Power of Power - Blog - Dynamic Background

supercerealoso supercerealoso: Dynamic Background

Some time ago I wanted to make a dynamic background for my other comic, Not ‘Super’ at All. I did that because I liked the idea of just one of the characters in the background but they all were important, so they all appear in the background once in a while.

 

To do this I used this code:

 

<style>

 .body1{background:url(http://path.to/image1.jpg);}

 .body2{background:url(http://path.to/image2.jpg);}

</style>

<script>

 numOfBgs = 2;

 var randomnumber = Math.floor(Math.random() * numOfBgs) + 1;

 document.body.className = "body" + randomnumber;

</script>

 

 

 

It´s really simple to add more backgrounds, you just have to change the line numOfBgs = 2; for the new number of Backgrounds and add a bodyX{background:url(http://path.to/imageX.jpg);} for every background Image.

 

I guess It may be useful for someone else...

Posted: 14th May 2013, 7:04 AM
Blog Archive:
RGB (25th Feb 2017, 2:04 AM)
Inktober (29th Oct 2016, 4:59 AM)
Cleaning sketches with GIMP and vectorization with Inkscape (7th Mar 2016, 2:35 AM)
100 Comic Strips!!! (31st Oct 2014, 12:26 AM)
Super Smash Bros. DRAWL 2 (30th Sep 2014, 1:31 AM)
I Maed a Font (12th Jul 2014, 5:43 AM)
New Top 10 (28th Jun 2014, 3:59 AM)
How Webcomics Work (8th May 2014, 5:29 AM)
Batman N' Robin (28th Apr 2014, 12:13 AM)
Valentine's Special (14th Feb 2014, 2:21 AM)
Best of Power of Power According to Reddit (7th Feb 2014, 4:00 AM)
Brush Your Teeth (29th Jan 2014, 3:55 AM)
Last Year's Drawings (6th Jan 2014, 6:11 AM)
Disco Time (1st Dec 2013, 6:18 AM)
Distinguished Octopus (1st Dec 2013, 2:48 AM)
Cookie Monster with Chocolate Bunny (1st Dec 2013, 1:47 AM)
Crazy Flash Animation (5th Nov 2013, 10:28 PM)
Top 10 (10th Sep 2013, 12:30 PM)
Reviews (10th Sep 2013, 12:21 AM)
Super Elvis (1st Jul 2013, 1:17 AM)
Disco Whale (25th Jun 2013, 6:11 AM)
Drawings by Request (25th May 2013, 12:49 AM)
Music Time (17th May 2013, 7:33 AM)
Dynamic Background (14th May 2013, 7:04 AM)
How I Make My Comics (10th May 2013, 1:42 PM)