У меня возникла проблема с получением функции с анимацией для работы во втором/закрывающемся щелчке. Он работает на первый щелчок, хотя ... Вот код:jQuery parent animate второй клик (закрыть/откат) не работает
HTML:
<div id="about">
<div id="aboutbtn-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
<div id="aboutbtn">About me</div>
<div class="social-icons">
<a href="#"><img src="http://placehold.it/43x43"></a>
<a href="#"><img src="http://placehold.it/43x43"></a>
</div>
</div>
CSS:
#about {
background: #336699;
height: 561px;
width: 300px;
position:absolute;
top: 0%;
right:-285px;
}
#aboutbtn {
background: #336699;
background-size: contain;
background-repeat: no-repeat;
width: 85px;
height: 35px;
text-align: center;
padding: 35px 10px;
font-size: 18px;
cursor: pointer;
color: #fff;
position: absolute;
left: -85px;
margin-top: 20px;
margin-right: 15px;
display: block !important;
}
#aboutbtn-content {
float: left;
padding: 35px 30px;
}
.social-icons {
position: absolute;
left: -63px;
top: 140px;
}
.social-icons img {
display: block;
margin-bottom: 10px;
}
Javascript:
$(document).ready(function() {
$("#aboutbtn").click(function() {
$(this).parent().animate({
right: '-280px'
}, {
queue: false,
duration: 500
});
}, function() {
$(this).parent().animate({
right: '0px'
}, {
queue: false,
duration: 500
});
});
});
Я сделал jsfiddle you can see by clicking here ,
У меня есть вдохновение from this fiddle, разница только в том, что я изменил его, чтобы переключиться.
Я не самый острый JS-кодер, поэтому, пожалуйста, несите меня: D. Буду признателен за любой ответ!
Заранее благодарен!