From f84920f40a4f00efef51ae5b971591500a8116da Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 9 Aug 2011 17:17:22 +0200 Subject: [PATCH] Smooth scroll effect added --- .../install/files/acp/templates/header.tpl | 1 + wcfsetup/install/files/js/WCF.js | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/wcfsetup/install/files/acp/templates/header.tpl b/wcfsetup/install/files/acp/templates/header.tpl index 51a4f910c0..287040f57c 100644 --- a/wcfsetup/install/files/acp/templates/header.tpl +++ b/wcfsetup/install/files/acp/templates/header.tpl @@ -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(); }); //]]> diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 7f1cb28805..fae2ff0475 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -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. */ -- 2.20.1