I have been working on a toggle script, but I find myself repeating my code. Is there a way of combining it all?
jQuery(document).ready(function($) {
var topContainer = $("#alles");
var topButton = $(".abutton");
topButton.click(function() {
topContainer.slideToggle(1200, 'easeInOutQuart');
$(".hideable").slideToggle(1200, 'easeInOutQuart');
});
var topContainer2 = $("#voorbeelden");
var topButton2 = $(".bbutton");
topButton2.click(function() {
topContainer2.slideToggle(1200, 'easeInOutQuart');
$(".hideable").slideToggle(1200, 'easeInOutQuart');
});
var topContainer3 = $("#contact");
var topButton3 = $(".cbutton");
topButton3.click(function() {
topContainer3.slideToggle(1200, 'easeInOutQuart');
$(".hideable").slideToggle(1200, 'easeInOutQuart');
});
});
.container {
display:block;
width:500px;
margin:0 auto;
}
.hideable {
width: 500px;
margin: 0 auto;
}
#alles {
float:left;
width:500px;
height:500px;
background:#ff4000;
}
#voorbeelden {
float:left;
width:500px;
height:100px;
border-top:1px solid #ddd;
background:#cc6600;
}
#contact {
float:left;
width:500px;
height:100px;
border-top:1px solid #ddd;
background:#bb3300;
}
.toggleable {
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<header>
<h1>stuff</h1>
<h2>more stuff</h2>
</header>
<div id="main" class="hideable"><img src="imgs/rk.svg" alt="image"></div>
<div id="alles" class="toggleable"></div>
<div id="voorbeelden" class="toggleable"></div>
<div id="contact" class="toggleable"></div>
<ul>
<li>
<a href="#" class="abutton">
<h2 class="orsp-title">a</h2>
<span class="orsp-category">stuff</span>
</a>
</li>
<li>
<a href="#" class="bbutton">
<h2 class="orsp-title">b</h2>
<span class="orsp-category">stuff</span>
</a>
</li>
<li>
<a href="#" class="cbutton">
<h2 class="orsp-title cbutton">c</h2>
<span class="orsp-category">stuff</span>
</a>
</li>
</ul>
</div> <!--/container-->