Skip to content

Instantly share code, notes, and snippets.

@MathRivest
Created July 25, 2014 17:38
Show Gist options
  • Select an option

  • Save MathRivest/8a51dad6e4237fdfff37 to your computer and use it in GitHub Desktop.

Select an option

Save MathRivest/8a51dad6e4237fdfff37 to your computer and use it in GitHub Desktop.
Small script to toggle part of the page
<button data-target="#target">Toggle</button>
<div id="target">Toggle me</div>
var toggleInit = function(){
var $button = $('[data-toggle]');
$button.on('click', function(evt){
$target = $($(this).attr('data-toggle'));
evt.preventDefault();
if($target.is(':visible')){
$target.animate({ opacity: 0 }, 200).slideUp(300);
}else{
$target.slideDown(300).animate({ opacity: 1 }, 200);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment