Why #cart does not return to the site if I scroll the page to the top. If instead of .animate use .css , then everything is done, but immediately executed top: 80px; and right: -180px; . Why?
$(window).scroll(function(){ if ($(window).scrollTop()>1){ $('#cart').animate({'top':'80px'}, 300); $('#cart').animate({'right':'-180px'}, 300); }else{ $('#cart').animate({'top':'20px'}, 300); $('#cart').animate({'right':'20px'}, 300); } }); Here is an example of how all of this works: https://jsfiddle.net/rx70x315/