Closed Thread Icon

Topic awaiting preservation: Random is CSS Pages that link to <a href="https://ozoneasylum.com/backlink?for=7981" title="Pages that link to Topic awaiting preservation: Random is CSS" rel="nofollow" >Topic awaiting preservation: Random is CSS\

 
Author Thread
KARN
Bipolar (III) Inmate

From: North Bay, Ontario, CA
Insane since: Apr 2001

posted posted 12-13-2001 03:33

in CSS... is there something like random; or something?

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 12-13-2001 05:30

As in....random...what?

I mean, what would you make random if there were such a thing?




{{edit - BTW: http://www.w3.org }}

[This message has been edited by DL-44 (edited 12-13-2001).]

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-13-2001 09:37

You can use JS to generate random (whatever) and then document.write() it.

Or you can use some server-side language like PHP, PERL, ASP, etc...


Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 12-13-2001 14:07

KARN: It all depends on what your question is. There is no such style as random and I'm not sure if any style has the attribute random (I can't think of one). If you want a random style sheet then we can do that (I've got one working).

You'll need to explain what you mean a bit better.

Emps


You're my wife now Dave

KARN
Bipolar (III) Inmate

From: North Bay, Ontario, CA
Insane since: Apr 2001

posted posted 12-14-2001 06:24

Sorry, should of been more specific... I have multiple splash background images and right now I have:

body { background: white url("1-Shards.jpg"); background-repeat:no-repeat; background-position: top left;}

I want it to load random ones say for a series:

body { background: white url("1-Shards.jpg"); background-repeat:no-repeat; background-position: top left;}
body { background: orange url("2-Ice.jpg"); background-repeat:no-repeat; background-position: top left;}
body { background: blue url("3-Explosion.jpg"); background-repeat:no-repeat; background-position: top left;}

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 12-14-2001 07:10

try this :

<script language="javascript">
backgrounds = new Array();
backgrounds[0] = 'path/to/first/background';
backgrounds[1] = 'path/to/second/background';
backgrounds[2] = 'path/to/third/background';

body.background = backgrounds[Math.floor(Math.random() * backgrounds.length)];


</script>


This is totally untested but should work



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

KARN
Bipolar (III) Inmate

From: North Bay, Ontario, CA
Insane since: Apr 2001

posted posted 12-15-2001 07:31

Is there a way to change the background colors too matching with different background images?

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-15-2001 12:06

document.bgColor = 'red';


Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 12-15-2001 16:58

KARN: Once you change the background colours you start to notice that other colours need changing too. What I'd recommend is that you actually swap the stylesheets randomly. I have a script that will do this and if you are using PHP it will make the job simpler. Its your call.

Emps

KARN
Bipolar (III) Inmate

From: North Bay, Ontario, CA
Insane since: Apr 2001

posted posted 12-16-2001 20:13

okay... can I get the script... I can attempt different things right now...

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 12-19-2001 20:49

KARN: Sorry for not getting back sooner (I've not been well and not been able to track down where I had the script!!) - try this (I've got it working so any problems are in the cut and paste so let me know if it goes wrong):

code:
<script language="JavaScript" type="text/javascript">
<!--
function setStyle (stylename) {
var lnk = document.getElementsByTagName("LINK")[0];
lnk.href = "css/" + stylename + ".css";
}

var style = new Array(4)
style[0] = "ozone";
style[1] = "gurus";
style[2] = "asylum";
style[3] = "etc";

function randomStyle () {
var randStyle = style[Math.floor( Math.random() * style.length )];
setStyle (randStyle);
}
//-->



And call it with <body onload="randomStyle ()">

You may need to change the path to the CSS files and if you are using PHP things can be streamlined somemore. It uses the DOM method for swapping styles but it can be used just as easily with the good doctor's version of a more crossbrower script.

Emps


You're my wife now Dave

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 12-19-2001 21:14

For cross browser compatiblity you can just dynamically write the tag

document.write("<LINK REL='stylesheet' TYPE='text/css' HREF='+stylename+'.css'>");



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

« BackwardsOnwards »

Show Forum Drop Down Menu