Friday 18 July 2014

How to Add Animated Back to Top Button in Blogger

I suppose you might have seen stylish and animated Back to Top button in several websites and blogs. In this tutorial I'll show you how to implement one in your Blogger Blog. It will look alike as in my blog. You can change the code and make it stylish according to the theme of your blog.

Step 1
Go to Blogger Dashboard. Select your blog and click on Template → Edit HTML.

Click on Edit HTML


Step 2
Now, press Ctrl + F and search for </head> tag.



Add the following code before it.

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
  2. </script>
  3. <style>
  4. .back-top {
  5.     background: #FFFFFF; // background color of Back to Top Button
  6.     color: #fff;
  7.     font: bold 24px/100% &quot;Times New Roman&quot;, Times, serif;
  8.     width: 30px;
  9.     height: 30px;
  10.     padding-top: 4px;
  11.     margin-bottom: 40px;
  12.     text-align: center;
  13.     text-decoration: none;
  14.     display: inline-block;
  15.     zoom: 1;
  16.     border-radius: 10em;
  17.     border-style:solid;
  18.     border-width:medium;
  19.     border-color:#000000
  20.     box-shadow: 0 2px 0 rgba(0,0,0,.1);
  21. }
  22. </style>
  23. <script type="text/javascript">
  24. jQuery(document).ready(function() {
  25.     var offset = 220;
  26.     var duration = 500; // duration of animation
  27.     jQuery(window).scroll(function() {
  28.         if (jQuery(this).scrollTop() > offset) {
  29.             jQuery('.back-top').fadeIn(duration);
  30.         } else {
  31.             jQuery('.back-top').fadeOut(duration);
  32.         }
  33.     });
  34.     jQuery('.back-top').click(function(event) {
  35.         event.preventDefault();
  36.         jQuery('html, body').animate({scrollTop: 0}, duration);
  37.         return false;
  38.     })
  39. });
  40. </script>

Step 3
Now find </body> tag. 


Copy the following code and paste before it.

  1. <center>
  2. <a class='back-top' href='#header'></a> // symbol indicating Back to Top
  3. </center>

Step 4
Now Save Template.  

No comments:

Post a Comment