Wednesday, October 31, 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. Well thanks too itechcolumn for this effect, 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']="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiUIlutFfcHs42Le_RP8LhLkJwdy03Oa61wDBNCuCcYrOJuA3AklyTUDMHUgRt9CtPr-IZJBWl2W3o9V0Xc9k6aTvOxi3O1-YQOo1YVCL2_KPhk6baChloA1Z5WtXoqJ0UHeggk-7MwxNo/s1600/Leaf1.png";
    image_urls['rain2']="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik2Tor2h2XlLa-CP4i9x_PL6tPTFRxk-DYh6C35tThmPJ6LNmF0o5erqrDd1NaHpQwoVmCLDwUdRTX6dtCfhquaSiPiOXsyVTJq46FhFVXLYhNGv7pwLBRA2djomfCqpvWWmPMJINSa9rq/s1600/Leaf2.png";
    image_urls['rain3']="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU-0uAlfa0gXwK4NFM_HM_w_dCkYTFY5UDrNPj0ykEfQ4PX47d1lIjDUUgVYwKyUQ16BO9gGl8oY4D-9kOXP4pyP7tsnqte-N77CZjFs2LJdpVdXIp7FkGACIchYncobYvLZHvxeYvEIJT/s1600/Leaf6.png";
    image_urls['rain4']="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmCobSSAZLJDjfaS8MJ09INVulk27LSucOZ-Mqld0eN4EadyUdCrQFPWm2q2t0buv0TUu_nv8f2vZAONXmKm7qUDKYGfRm0a_Xi8b-FPJVRaJ9M-AAKS-l-3TWU9PsBwSuAsOesdeop37F/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 :)

No comments:

Post a Comment

 

Pages

About Me

Bookmark & Share