Skip to content

Instantly share code, notes, and snippets.

@onishiweb
Created July 11, 2012 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onishiweb/3089751 to your computer and use it in GitHub Desktop.
Save onishiweb/3089751 to your computer and use it in GitHub Desktop.
Sliding sections using jQuery
slidingSections = function () {
var $container = $(".sliding-content");
var $titles = $("h3", $container);
$(".section", $container).slideUp(0).width(460).hide(); // CM: setting width here to stop the dreaded slidedown jump :)
$titles.css("cursor", "pointer").append(' <span>(click to expand)</span>');
$container.on( "click", "h3", function () {
$(".section").slideUp();
$titles.removeClass("active");
var $this = $(this);
if ($this.next().is(":hidden"))
{
$this.addClass("active");
$this.next().stop().slideDown(1000);
}
else
{
$this.removeClass("active");
$this.next().stop().slideUp(1000);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment