I made the button "up" for the site, and I want it to appear smoothly when scrolling down the page (as in VK), but so that its transparency depended on the scroll distance. Such code turned out:
var h = window.outerHeight, t = window.innerHeight, r = 0; $(window).scroll(function() { r = $(window).scrollTop() - t; if (r > getDocumentHeight() - 200) { $('#ToTop').css({ opacity: 1 }); $('#ToTop').css({ display: 'block' }); } if (r > 0) { var op = r / 1000; $('#ToTop').css({ opacity: op }); $('#ToTop').css({ display: 'block' }); } else $('#ToTop').css({ display: 'none' }); }); But the problem is that the numbers of the transparency in the CSS are changing, but the button itself changes only when the page scroll stops. For example, the "Up" button in VC changes the transparency during the scrolling process. Tell me how this can be implemented.