HackingUniversity - Hacks . Tricks . How-To's

31 March 2013

Automatically Change Background Color on Refresh in Blogger

blogger-logoHave you ever wondered to provide your visitors with a fresh look everytime they refresh your blog or maybe visit one or another article, well now with easy CSS and JavaScript's hacks you can apply few easy tweaks that can make your work a lot easier. Well yes we are talking about changing our blog's background color everytime a person refreshes your blog, so he would be greeted with a new background color.

So I do not have any demo for this effect but I am using this effect at the time of posting this article so if you are reading this article pretty late you might not be able to see this effect, but it's a simple CSS overriding effect so it simply adds a new color HEX code everytime a person refresh's your blog and color's are randomly selected. So if you wish to add this effect to your blogger blog just check below  steps.

  1. Open Blogger > Template > Edit HTML.
  2. Now press Ctrl + F and search for </head> tag & paste below code above it.

    <script>$(function(){function e(){return"rgb("+Math.round(Math.random()*255)+", "+Math.round(Math.random()*255)+", "+Math.round(Math.random()*255)+")"}$("body").each(function(t){$(this).css("background",e())})})</script>

  3. Now just Save Template and refresh your blog to see this effect.

So now everytime you refresh your blog you will see background color changing randomly, so you open any post and you will see different color. So that's it hope you guys liked this article, if you find any problem do comment.