Free mobile recharge for 10 lucky winners participate in this giveaway
HackingUniversity - Hacks . Tricks . How-To's

20 September 2012

How to add Leaf Falling Effect in Blogger using JavaScript

Adding effects like snow falling, stars falling and hearts falling have been posted earlier on this blog, but this is another version of falling leaves in blogger for giving it much more natural look, combined by nature. Well this effect is simply created using images and jQuery and it works everytime someone visits your blog and he see leaves falling from top. So jump in too below tutorial and have fun.

falling-leaves

  1. Go to Blogger > Layout > Add Gadget.
  2. Now you just need to choose HTML/JavaScript Gadget and add the below JavaScript code to it.

    <script>
    if(typeof jQuery=='undefined'){document.write('<'+'script');document.write(' language="javascript"');
    document.write(' type="text/javascript"');
    document.write(' src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">');
    document.write('</'+'script'+'>')}
    </script>
    <script>
    if(!image_urls)
    {var image_urls=Array()}if(!flash_urls)
    {var flash_urls=Array()}image_urls['rain1']="http://2.bp.blogspot.com/-kZFDYYz6KGk/UFmgFdC62TI/AAAAAAAAEX8/smhTZsHE-O8/s1600/Leaf1.png";
    image_urls['rain2']="http://1.bp.blogspot.com/-i705daAePrk/UFmgGIvxZaI/AAAAAAAAEYE/DQb3DElqJO4/s1600/Leaf2.png";
    image_urls['rain3']="http://2.bp.blogspot.com/-jrQRo6CcvEg/UFmgJOJAJ_I/AAAAAAAAEYk/efOE-PMw1Ls/s1600/Leaf6.png";
    image_urls['rain4']="http://3.bp.blogspot.com/-Te-t2fE8zBY/UFmgIXY063I/AAAAAAAAEYc/P5OT_IQhqPQ/s1600/Leaf5.png";
    $(document).ready(function(){var c=$(window).width();var d=$(window).height();
    var e=function(a,b){return Math.round(a+(Math.random()*(b-a)))};
    var f=function(a){setTimeout(function(){a.css({left:e(0,c)+'px',top:'-30px',display:'block',opacity:'0.'+e(10,100)}).animate({top:(d-10)+'px'},e(7500,8000),function(){$(this).fadeOut('slow',function(){f(a)})})},e(1,8000))};
    $('<div>
    </div>
    ').attr('id','rainDiv')
    .css({position:'fixed',width:(c-20)+'px',height:'1px',left:'0px',top:'-5px',display:'block'}).appendTo('body');for(var i=1;i<=20;i++){var g=$('<img/>').attr('src',image_urls['rain'+e(1,4)])
    .css({position:'absolute',left:e(0,c)+'px',top:'-30px',display:'block',opacity:'0.'+e(10,100),'margin-left':0}).addClass('rainDrop').appendTo('#rainDiv');f(g);g=null};var h=0;var j=0;$(window).resize(function(){c=$(window).width();d=$(window).height()})});
    </script>
    <script>
    if(typeof jQuery=='undefined'){document.write('<'+'script');document.write(' language="javascript"');
    document.write(' type="text/javascript"');document.write(' src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">');
    document.write('</'+'script'+'>')}
    </script>

  3. Now code contains some image urls that contain leaf images which you can change according to your preference.
  4. So that’s it now Save the Template and refresh your blog to see the new effect. Well you can also replace the leaf images with other objects and create new effects, explore yoru creativity have fun :)