Fancy JQuery social sidebar slider

In this tutorial, I will show you how to make a fancy social jQuery sidebar like the one overhere. If you think its too fancy for you, I will also show you how to make an animation like this one.

Nice? Well lets get started!

MARKUP

First up, we need to have some markup. You can place this in your <body> tag, OUTSIDE any other tags:

</pre>
<div id="socialicons"><a href="http://www.facebook.com/" target="_blank">
</a><a href="http://www.facebook.com/" target="_blank">
 </a>
<a href="http://www.twitter.com/" target="_blank">
</a><a href="http://www.twitter.com/" target="_blank">
 </a>
<a href="http://www.youtube.com/user/" target="_blank">
</a><a href="http://www.youtube.com/user/" target="_blank">
 </a></div>
<pre>

Nothing much there, just a main “social icon” container with a three div containers.

CSS

Next, lets style this markup using some CSS. We’re going to use an image sprite to improve performance.


#socialicons {
position: absolute;
top:20px;
left:0px;
}

#facebook {
margin-left: -92px;
width: 109px;
height: 26px;
background: url(images/social.png);
background-position: 0px 0px;
cursor: pointer;
}

#twitter {
margin-top: 20px;
margin-left: -92px;
width: 109px;
height: 30px;
background: url(images/social.png);
background-position: 0px -55px;
cursor: pointer;
}

#youtube {
margin-top: 20px;
margin-left: -92px;
width: 109px;
height: 26px;
background: url(images/social.png);
background-position: 0px -30px;
cursor: pointer;
}

We’re using a sprite and only one image to minimize the HTTP GET requests (and increase performance).
There’s an image you need to save at this point. create a folder name “images” and save ONE of the following images in that folder. save the image as “social.png”:

whiteblack

SCRIPT

Finally, the script. The script is jQuery mainly, so you need to add the following JQuery library in the <head> tag.:


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

And finally, the following JQuery script (in the <head> tag :

$("#facebook,#twitter,#youtube").hover(function(){
$(this).stop().animate({marginLeft:"0px"}, 600,
function()
{
$(this).animate({marginLeft:"-50px"},346,
function()
{
$(this).animate({marginLeft:"0px"},346);
});
});

},
function()
{
$(this).stop().animate({marginLeft:"-92px"}, 300);
});

This is the more fancy script, the one that goes out and back in again. If you simply want it to slide outwards, replace the above script with this:

$("#facebook,#twitter,#youtube").hover(function(){
$(this).stop().animate({marginLeft:"0px"}, 600);

},
function()
{
$(this).stop().animate({marginLeft:"-92px"}, 300);
});

And that’s it! I hope you enjoyed the tutorial, if you shall have any questions, please comment bellow.

_Sand
// ]]>

This entry was posted in JQuery, Tutorial. Bookmark the permalink.

4 Responses to "Fancy JQuery social sidebar slider"

Leave a reply


3 + = eleven