Last active
December 20, 2015 17:49
-
-
Save nickescobedo/6171092 to your computer and use it in GitHub Desktop.
Ben example from comment on http://nickescobedo.com/338/how-to-use-one-javascript-function-to-slide-any-html-element-up-and-down-with-jquery
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
<button onClick="slideContent('content1')">Content 1</button> | |
<button onClick="slideContent('content2')">Content 2</button> | |
<div id="content1"> | |
<p>Sliding paragraph</p> | |
</div> | |
<div id="content2"> | |
<p>Sliding paragraph</p> | |
</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
function slideUpDown(slider){ | |
if($("#" + slider).is(":hidden")) | |
$("#" + slider).slideDown('slow'); | |
else | |
$("#" + slider).slideUp('slow'); | |
} | |
function slideContent(content){ | |
if(content == 'content2'){ | |
//If one of the contents are hidden and one is visible slide one up and slide the other down | |
if($('#content2').is(":hidden") && $("#content1").is(":visible")){ | |
slideUpDown('content1'); | |
slideUpDown('content2'); | |
} | |
//If one of the contents are hidden and one is visible slide one up and slide the other down | |
else if($('#content1').is(":hidden") && $("#content2").is(":visible")){ | |
slideUpDown('content1'); | |
slideUpDown('content2'); | |
} | |
//Else they are either both up or down so slide only one of them | |
else{ | |
slideUpDown(content); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment