Smooth scroll effect added
authorMarcel Werk <burntime@woltlab.com>
Tue, 9 Aug 2011 15:17:22 +0000 (17:17 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 9 Aug 2011 15:17:22 +0000 (17:17 +0200)
wcfsetup/install/files/acp/templates/header.tpl
wcfsetup/install/files/js/WCF.js

index 51a4f910c0dd33f2b2e1bcc450ef0460bb5051d4..287040f57c1353bf3d77079d105ff0329b2eaf23 100644 (file)
@@ -68,6 +68,7 @@
                                'wcf.global.page.previous': '{capture assign=pagePrevious}{lang}wcf.global.page.previous{/lang}{/capture}{@$pagePrevious|encodeJS}'
                        });
                        new WCF.Date.Time();
+                       new WCF.Effect.SmoothScroll();
                });
                //]]>
        </script>
index 7f1cb28805d85f9dab9bfe1f53bb05c9388e2a28..fae2ff0475d29a952eec814631c5735c11732d8d 100644 (file)
@@ -1540,6 +1540,39 @@ WCF.User = {
        }
 };
 
+/**
+ * Namespace for effect-related functions.
+ */
+WCF.Effect = {};
+
+/**
+ * Creates a smooth scroll effect.
+ */
+WCF.Effect.SmoothScroll = function() { this.init(); };
+WCF.Effect.SmoothScroll.prototype = {
+       /**
+        * Initializes effect.
+        */
+       init: function() {
+               $('a[href=#top],a[href=#bottom]').click(function() {
+                       var $target = $(this.hash);
+                       if ($target.length) {
+                               var $targetOffset = $target.getOffsets().top;
+                               if ($targetOffset > $(document).height() - $(window).height()) {
+                                       $targetOffset = $(document).height() - $(window).height();
+                                       if ($targetOffset < 0) $targetOffset = 0;
+                               }
+                               
+                               $('html,body').animate({ scrollTop: $targetOffset }, 1200, function (x, t, b, c, d) {
+                                       return -c * ((t=t/d-1)*t*t*t - 1) + b;
+                               });
+                               
+                               return false;
+                       }
+               });
+       }
+};
+
 /**
  * Basic implementation for WCF dialogs.
  */