Created
July 25, 2014 17:38
-
-
Save MathRivest/8a51dad6e4237fdfff37 to your computer and use it in GitHub Desktop.
Small script to toggle part of the page
This file contains hidden or 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
| <button data-target="#target">Toggle</button> | |
| <div id="target">Toggle me</div> |
This file contains hidden or 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
| 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