Thank you. Your comment will be posted following moderation.
Please complete the form to post your comment.
{ a resource for web designers & developers }
RSS feed Twitter Flickr YouTube

A jQuery-powered social dropdown menu

When David Walsh posted his article on using jQuery's sliding effect for use in FAQs, I was once again reminded of the beauty of jQuery in its simplicty. I thought I'd take it a step further and show how it could be used for a static dropdown menu for your site/blog's social media links.

As David's tutorial outlines, it's a matter of applying a slide effect to display a DIV when th H3 handler is clicked. I won't break it down here for the sake of saving you time but you can view his tut and demo if you wish.

Features @ a glance

I've tested it across browsers but, as mentioned, there are some positioning issues with IE6.

The XHTML markup:

<!-- BEGIN SOCIAL MENU DEMO -->
<div id="MySocialMenu">
<h3>My Social Links</h3>

<!-- THIS IS THE HIDDEN LIST THAT SLIDES IN ON CLICK -->

<div id="SocialMenu">
<ul>
<li class="rss"><a href="#" title="Subscribe to my feed">Subscribe RSS</a></li>
<li class="twitter"><a href="#" title="Follow me on Twitter">Twitter</a></li>
<li class="buzz"><a href="#" title="Come see what the buzz is about">Google Buzz</a></li>
<li class="facebook"><a href="#" title="Let's connect on Facebook">Facebook</a></li>
<li class="flickr"><a href="#" title="Peruse my Flickr gallery">Flickr</a></li>
</ul>
</div>

</div>
<!-- END SOCIAL MENU DEMO -->

The jQuery:

//David's script with a change to the DIV ID

$(document).ready(function() {
	$('#MySocialMenu h3').each(function() {
		var tis = $(this), state = false, answer = tis.next('div').hide().css('height','auto').slideUp();
		tis.click(function() {
			state = !state;
			answer.slideToggle(state);
			tis.toggleClass('active',state);
		});
	});
});

Pretty it up with some CSS:

#MySocialMenu {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 220px;
  min-height: 20px;
  margin: 0;
  background: #222;
  cursor: pointer;
  border: 3px solid #666;
  /* OPTIONAL CSS3 DROPSHADOW */
  -webkit-box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2);
  -moz-box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2);
  z-index: 1000;
}

#MySocialMenu h3 {
  display: block;
  font-size: 1.2em;
  font-weight: bold;
  line-height: 20px;
  color: #fff;
  margin: 0;
  padding: 15px 0 15px 40px;
  background: url(../img/toggle-arrow.gif) no-repeat; /* SPRITE TO REDUCE IMAGE NEEDS*/
}

#MySocialMenu h3.active {
  color: #ff0084;
  background: url(../img/toggle-arrow.gif) 0px -50px no-repeat; /* SPRITE TO REDUCE IMAGE NEEDS*/
}


/* THIS IS THE HIDDEN MENU */

#SocialMenu {
  height: 0;
}

#SocialMenu ul {
  margin: -7px 0 7px 0;
  padding: 0 20px;
  list-style: none;
}

#SocialMenu ul li {
  font-size: 1.0em;
  line-height: 36px;
  margin: 0;
  padding: 7px 0 7px 40px; /* LEFT PADDING ACCOUNTS FOR THE ICONS */
}

#SocialMenu ul li a {
  display: block;
  color: #fff;
  text-decoration: none;
}

#SocialMenu ul li a:hover {
  color: #999;
  text-decoration: none;
}

/* ADDS ICONS TO EACH LIST ITEM */

#SocialMenu ul li.rss {
  background: url(../img/rss.png) left no-repeat;
}

#SocialMenu ul li.twitter {
  background: url(../img/twitter.png) left no-repeat;
}

#SocialMenu ul li.buzz {
  background: url(../img/google.png) left no-repeat;
}

#SocialMenu ul li.facebook {
  background: url(../img/facebook.png) left no-repeat;
}

#SocialMenu ul li.flickr {
  background: url(../img/flickr.png) left no-repeat;
}

This method shows just how versatile jQuery is. There are many other ways you can use this approach for navigation and content display. Play with it on your own and see what you can come up with.

Stay well.





Set Phasers on Fun!

Skyrocket Labs is a resource for beginner to advanced web designers & developers, offering original jQuery scripts & design tools, insight into best practices and industry trends and, more importantly, dedicated to celebrating and exchanging with the vast and amazing talent in the designer/developer community. It's about learning, sharing, growing and having a blast.

In the Community

CSS Globe Speckyboy Usability Post Peter Hinton Design Blue Awesome AEXT Smashing Magazine Six Revisions Janko at Warp Speed