Skip to content

Instantly share code, notes, and snippets.

@nickescobedo
Last active December 20, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickescobedo/6171092 to your computer and use it in GitHub Desktop.
Save nickescobedo/6171092 to your computer and use it in GitHub Desktop.
<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>
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