I am trying to create a toggle menu that shows and hides itself without requiring the button to be clicked twice. I have added e.preventDefault(); which solves the issue, but now the button does not transform as intended.
$(document).ready(function() {
$(".spinner-master2").click(function() {
$(".slideme").toggle("slow", function() {});
});
});
.slideme {
background-color: rgba(183, 221, 240, 0.88);
width: 100%;
height: 150px;
display: none;
}
.spinner-master2 * {
transition: all 0.3s;
-webkit-transition: all 0.3s;
box-sizing: border-box;
}
.spinner-master2 {
position: fixed;
top: 100px;
left: 50%;
margin: 0px auto;
height: 50px;
width: 50px;
}
.spinner-master2 input[type=checkbox] {
display: none;
}
.spinner-master2 label {
cursor: pointer;
position: absolute;
z-index: 99;
height: 100%;
width: 100%;
top: 0px;
left: 0;
}
.spinner-master2 .spinner2 {
position: absolute;
height: 5px;
width: 100%;
background-color: #000;
}
.spinner-master2 .diagonal.part-1 {
position: relative;
float: left;
}
.spinner-master2 .horizontal {
position: relative;
float: left;
margin-top: 7px;
}
.spinner-master2 .diagonal.part-2 {
position: relative;
float: left;
margin-top: 6px;
}
.spinner-master2 input[type=checkbox]:checked ~ .spinner-spin2 > .horizontal {
opacity: 0;
}
.spinner-master2 input[type=checkbox]:checked ~ .spinner-spin2 > .diagonal.part-1 {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
margin-top: 10px;
}
.spinner-master2 input[type=checkbox]:checked ~ .spinner-spin2 > .diagonal.part-2 {
transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
margin-top: -16px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="image"></div>
<div id="logo">js moody</div>
<div class="slideme">
</div>
<div id="menu" class="spinner-master2">
<input type="checkbox" id="spinner-form2" />
<label for="spinner-form2" class="spinner-spin2">
<div class="spinner2 diagonal part-1"></div>
<div class="spinner2 horizontal"></div>
<div class="spinner2 diagonal part-2"></div>
</label>
</div>