Skip to content

Instantly share code, notes, and snippets.

@tybruffy
Last active December 13, 2015 19:18
Show Gist options
  • Save tybruffy/4962066 to your computer and use it in GitHub Desktop.
Save tybruffy/4962066 to your computer and use it in GitHub Desktop.
Code for sliding open hidden content left/right
<div class="slider-container">
<label class="slider-trigger">Join Our Mailing List</label>
<input type="text" class="slider-target" data-width="206px" data-padding="5px" />
</div>
$(".slider-target").css({
width: "0px",
paddingLeft: "0px",
paddingRight: "0px"
});
$(".slider-trigger").click(function() {
var $target = $(this).closest(".slider-container").find(".slider-target")
, toWidth = $target.data("width")
if ($target.outerWidth() == parseInt(toWidth)) {
var width = padding = "0px"
} else {
var width = toWidth
, padding = $target.data("padding")
}
$target.stop(true, true)
.animate({
width: width,
paddingLeft: padding,
paddingRight: padding
}, "normal");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment