Sunday, 11 October 2009

Rotating Header Image[Images changes randomly with each refresh]

Rotating image Header for blogger?

IF you are here finding this question then this might be helpful.
We have a simple enough JavaScript that randomly calls for a new Header banner or Blog background image whenever the Blog is refreshed. This is useful if you have several background pictures which are suitable for your Blog and you want to showcase all of them.
I have used this effect to some extent on this blog.

Demo :Refresh The page(F5) and see a different image on my header.

 Mine CSS code before applying this hack-

body {
    background:#fff url( no-repeat top center;
    color: #4c4b4c;
    font-size: 12px;
    font-family:Arial, Sans-Serif,tahoma, Verdana;
    text-align: left;
    margin: 0 auto 0;
    padding-right: 5px;

Basically this script works by overwriting the 'background' definition at the <body> part of the template.

I wrote the following right after the <body> tag:

<script type='text/javascript'>

var banner= new Array()


var random=Math.round(6*Math.random());

document.write("body {");
document.write(&#39; background:url("&#39;   banner[random]   &#39;") no-repeat TOP;&#39;);
document.write(" }");


What we are doing is actually we are overwriting CSS for my body with this javascript.

Final Note : In my template my body covers  the header image which will not be the case in most of the template.SO you might have to replace .body with #header or #header-inner

Try this trick and tell me if it works for you...!!

No comments:

Post a Comment