Add Floating Share Buttons Like Mashable to Blogger

You must have seen in many Wordpress blogs including Mashable that they use floating share buttons. Now it’s time for Blogger to add a floating share buttons widget. In this tutorial I will tell you the method that can be used to implement this widget to Blogger by using the features of jQuery. It will appear outside of your post sections and as you scroll the page, this widget will also scroll with some animation effects.

Floating Share box using jQuery

Demo

Step 1. Go to Design > Edit HTML tab and check “Expand Widget Templates”. Find <data:post.body/> and before this snippet add:

<b:if cond='data:blog.pageType == "item"'>
<div id='sharebox'>
<div class='wdt'> Tweet Button </div>
<div class='wdt'> Facebook Share </div>
<div class='wdt'> StumbleUpon </div>
<div class='wdt'> Digg </div>
<div class='wdt'> The bookmarking button you want to add next </div>
</div>
</b:if>

Add your share buttons scripts between “<div class=’wdt’>add the share button code</div>”. You can get script codes from the bookmarking sites that you may like to add or you can also see my blog posts labeled as Button Counter or in the demo itself or in the normal floating share buttons. Here is an example to how to add the codes:

<div class='wdt'><script src="http://www.stumbleupon.com/hostedbadge.php?s=5"></script></div>

Step 2. Add the latest jQuery library immediately after ]]></b:skin>.

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' type='text/javascript'></script>

If you have previously added it, then you need not to add another one, just check whether it’s the latest or not and then replace it.

Step 3. Next is to add the JavaScript which will make the share box to float like Mashable that I have find out from CSS Tricks and modified a little by adding “.ready()” function. Find </head> and before it add:

<script type='text/javascript'>
$(document).ready(function() {

var $sidebar   = $("#sharebox"),
$window    = $(window),
offset     = $sidebar.offset(),
topPadding = 15;

$window.scroll(function() {
if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
});
} else {
$sidebar.stop().animate({
marginTop: 0
});
}
});

});
</script>

Step 4. Now is the CSS part. Add the below styling properties above ]]></b:skin>:

#sharebox {
float: left;
margin-left: -80px;
background: #992211;
position: absolute;
-moz-border-radius: 5px;
border-radius: 5px;
}
#sharebox .wdt {
float: left;
clear: left;
padding: 5px;
}

If you want the share box widget to float further left to your post body section, then increase the margin-left pixel value (marked in red) and if you want it to float closer then decrease it.

Step 5. Save your template.

If you are good with CSS then you can get different styles with it and give the floating share box a new look.

Popular posts from this blog

How to Resize Blogger Header to Logo Size

Google Penguin update hit me Hard