When I press the button I animate my .header_inner to move downwards. But how do I make it to go back to its original position when I press the button again or to animate it moving upwards?
Code:
<script>
$('.handler').click(function(){
$('.header_inner').animate({
top:"-=-28%",
}, 300);
});
</script>
I want my .header_inner to animate its way back again when I press the button again.
You can create a boolean variable that indicates whether the last movement was upwards or downwards:
var upwards = false,
newTop;
$('.handler').click(function(){
if (upwards) newTop = '28';
else newTop = '-28';
$('.header_inner').animate({
top:"-=" + newTop + "%",
}, 300);
upwards = !upwards;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With