Results 1 to 2 of 2

Thread: Div - Switcher, And Random

  1. #1
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Div - Switcher, And Random

    Hey,

    I'm currently working on a layout which allows the users to change the picture in the Logo, And also change the colour theme of the layout

    So in my header i have two Divs ( example )

    <Div Id="Banner1">
    <Div Id="Text">
    </Div>
    </Div>

    Now in each stylesheet ( changed by styleswitcher )

    Banner1 Will have the same values.

    But in text, the Background will be a different image depending on the color.

    So with the text sorted, so it changes when the user wants.

    I need the banner to be changeable

    I want links like

    Banner 1
    Banner 2

    so when the user clicks banner2 banner1 will change to banner2.

    So i need a script that can change a certain divs name.

    so on demand <Div Id="Banner1"> changes to <Div Id="Banner2">

    Which will change the background image.

    Now your probably thinking why dont i just make it a picture and change it.

    Because i need it a background so i can stick the text over it.

    So basically i just need a script that changes banner1 to banner2

    But so that both divs comply to the stylesheet on the main page.

    Also i need a way onload that the Banner div will randomly become either banner1, banner2, banner3 Etc.

    Thanks in advance, if you need more explaning, or you can't work out what im trying to so, just say i'll help.

    Alex.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Here's a basic example to keep you going:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    *{margin:0px;padding:0px;}
    #wrap{width:700px;padding:10px;margin:20px auto;border:3px double #777;
    font-family:arial,serif,helvetica;
    font-size:10pt;
    }
    #banner1{background:#9c0;height:50px;line-height:30px;text-align:center;}
    #banner2{background:#930;height:50px;line-height:30px;text-align:center;color:#eee;}
    #banner3{background:#eee;height:50px;line-height:30px;text-align:center;color:#222;}
    </style>
    <script type="text/javascript">
    window.onload=function(){
    var banner=['banner1','banner2','banner3'], // Set all of the banner in this array
    rand=Math.floor(Math.random()*banner.length),
    targ=document.getElementById('wrap').getElementsByTagName('div')[0];
    targ.setAttribute('id',banner[rand]); // This is to randomly assign an id to our div
    targ.onclick=function(){ var i=targ.id.split('banner')[1];
    if(i==3) this.setAttribute('id','banner1');
    else this.setAttribute('id','banner'+(Number(i)+1));
    }
    }
    </script>
    </head>
    <body>
    	<div id="wrap">
    	<div id="banner1">
    	This is the text inside the banner.
    	</div>
    	</div>
    </body>
    </html>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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
  •