Pages

 

Tuesday, February 21, 2012

How to Add Random Rotating Images to the Header of Your Blogger Blog

2 comments
In this short tutorial I am going to show you how to add random rotating images to your Blogger blog’s header background. After adding this neat feature to your blogger blog, the header image of your blog will rotate/change with each page refresh. Before implementing this tweak, you need to create (or find) header images that suit the topic of your blog. In this tutorial I am going to show how to rotate 5 header images.
How to add random rotating images to the header of your Blogger blog
1. Log in to Blogger, then go to Dashboard --> Design --> Edit HTML.
2. Find (Ctrl + F) the <body> tag.
3. Copy the following code and paste it immediately below the <body> tag.
 
<script type='text/javascript'>

var HeaderImage= new Array()
 
HeaderImage[0]=&quot;URL-OF-HEADER-IMAGE-1&quot;
HeaderImage[1]=&quot;URL-OF-HEADER-IMAGE-2&quot;
HeaderImage[2]=&quot;URL-OF-HEADER-IMAGE-3&quot;
HeaderImage[3]=&quot;URL-OF-HEADER-IMAGE-4&quot;
HeaderImage[4]=&quot;URL-OF-HEADER-IMAGE-5&quot;
var random=Math.round(4*Math.random());
 
document.write(&quot;<style>&quot;);
document.write(&quot;#header-wrapper {&quot;);
document.write(&#39; background:url(&quot;&#39; + HeaderImage[random] + &#39;&quot;) no-repeat left TOP;&#39;);
document.write(&quot; }&quot;);
document.write(&quot;</style>&quot;);
  </script>
 
Important note: Replace "URL-OF-HEADER-IMAGE-X" with the URLs of your images.
If the above code doesn't work for your blog, then replace "#header-wrapper" with "#header". (ID or Class of your header section).
You can add any number of images, it doesn’t have to be 5. But remember to change "4*Math.random()" according to the number of images you want to add. For example, if you want to add 8 different images to your blog header background, the code should be changed to "7*Math.random()". Look at the following example:
 
<script type='text/javascript'>

var HeaderImage= new Array()
 
HeaderImage[0]=&quot;URL-OF-HEADER-IMAGE-1&quot;
HeaderImage[1]=&quot;URL-OF-HEADER-IMAGE-2&quot;
HeaderImage[2]=&quot;URL-OF-HEADER-IMAGE-3&quot;
HeaderImage[3]=&quot;URL-OF-HEADER-IMAGE-4&quot;
HeaderImage[4]=&quot;URL-OF-HEADER-IMAGE-5&quot;
HeaderImage[4]=&quot;URL-OF-HEADER-IMAGE-6&quot;
HeaderImage[4]=&quot;URL-OF-HEADER-IMAGE-7&quot;
HeaderImage[4]=&quot;URL-OF-HEADER-IMAGE-8&quot;
var random=Math.round(7*Math.random());
 
document.write(&quot;<style>&quot;);
document.write(&quot;#header-wrapper {&quot;);
document.write(&#39; background:url(&quot;&#39; + HeaderImage[random] + &#39;&quot;) no-repeat left TOP;&#39;);
document.write(&quot; }&quot;);
document.write(&quot;</style>&quot;);
 </script>
 
4. Save your template. Refresh your site few times to see the result. Your header image will be rotate.

2 comments:

Unknown said...

you need to create (or find) header images that suit the topic of your blog. In this tutorial I am going to show how to rotate 5 header images.



garbage removal Brampton

Anonymous said...

This is a good posting, I was wondering if I could use this write-up on my website, I will link it back to your website though.




substance treatment

Post a Comment