]> git.mxchange.org Git - friendica.git/commitdiff
[frio] Improve back to top button behavior at bottom of page
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 9 Feb 2020 23:14:06 +0000 (18:14 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 9 Feb 2020 23:14:06 +0000 (18:14 -0500)
view/theme/frio/js/theme.js

index 8fc0d530123d3d681d7ed716cc606d04e96def4d..29d043a6a41ebaf1ab7cfbc82c83c77dae399f2d 100644 (file)
@@ -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;
                }
        });