Reputation: 39
When I click the button the page goes up but I want the button going to back. How can I do that?
$("#toUp").click(function(){
$("html,body").stop().animate({ scrollTop: "0" }, 1000);
$(this).animate({bottom:"auto",top:"0"},1000);
setTimeout(function(){
$("#toUp").css({top:"auto",bottom:"10"});
}, 1000);
});
Codepen : My Codepen Project
Upvotes: 1
Views: 76
Reputation: 5411
In the end of the animation, it adds top: 0
to the #toUp
element.
So, consider adding 100ms to the setTimeout method (i.e. 1100ms).
$("#toUp").click(function(){
$("html,body").stop().animate({ scrollTop: "0" }, 1000);
$(this).animate({bottom:"auto",top:"0"},1000);
setTimeout(function(){
$("#toUp").css({top:"auto",bottom:"10"});
}, 1100);
});
Upvotes: 1