SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Random Colours

  1. #1
    I'm a college yuppie now! sbdi's Avatar
    Join Date
    Jul 2000
    Location
    Dublin , Ireland
    Posts
    1,271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random Colours

    Can anyone point me in the direction of a script that can do the following

    I have a small paragraph , I want all the colours in the paragraph to be 1 or 4 colours. Anyone help me out ?
    Back Again

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like this?
    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    			function c()
    			{
    				var i = Math.floor(4 * Math.random());
    				switch(i)
    				{
    					case 0: 
    						return "#ff0000";
    						break;
    					case 1: 
    						return "#00ff00";
    						break;
    					case 2: 
    						return "#0000ff";
    						break;
    					case 3: 
    						return "#ffff00";
    						break;
    				}
    			}
    		</script>
    	</head>
    	<body onload="document.getElementById('p1').style.color = c();">
    		<p id="p1">Some text</p>	
    	</body>
    </html>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •