Last active
December 13, 2015 19:18
-
-
Save tybruffy/4962066 to your computer and use it in GitHub Desktop.
Code for sliding open hidden content left/right
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".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