From 5930d94c916cb233e510c676de3e74196a8accab Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 9 Feb 2020 18:14:06 -0500 Subject: [PATCH] [frio] Improve back to top button behavior at bottom of page --- view/theme/frio/js/theme.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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; } }); -- 2.39.5