From: Hypolite Petovan Date: Sun, 9 Feb 2020 23:14:06 +0000 (-0500) Subject: [frio] Improve back to top button behavior at bottom of page X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5930d94c916cb233e510c676de3e74196a8accab;p=friendica.git [frio] Improve back to top button behavior at bottom of page --- diff --git a/view/theme/frio/js/theme.js b/view/theme/frio/js/theme.js index 8fc0d53012..29d043a6a4 100644 --- a/view/theme/frio/js/theme.js +++ b/view/theme/frio/js/theme.js @@ -3,11 +3,21 @@ var jotcache = ''; //The jot cache. We use it as cache to restore old/original j $(document).ready(function(){ //fade in/out based on scrollTop value + var scrollStart; + $(window).scroll(function () { - if ($(this).scrollTop() > 1000) { - $("#back-to-top").fadeIn(); - } else { + let currentScroll = $(this).scrollTop(); + + // Top of the page or going down = hide the button + if (!scrollStart || !currentScroll || currentScroll > scrollStart) { $("#back-to-top").fadeOut(); + scrollStart = currentScroll; + } + + // Going up enough = show the button + if (scrollStart - currentScroll > 100) { + $("#back-to-top").fadeIn(); + scrollStart = currentScroll; } });