From 19ac23fd53792526cff425b67424492cb0a51a2b Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 14 Nov 2014 21:48:17 +0200 Subject: [PATCH] Initial Commit --- index.html | 4 +--- index.html~ | 2 +- js/scroll.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 js/scroll.js diff --git a/index.html b/index.html index 37f9f45..a5d5f93 100644 --- a/index.html +++ b/index.html @@ -29,8 +29,6 @@
IP
- - - + \ No newline at end of file diff --git a/index.html~ b/index.html~ index 59100d0..37f9f45 100644 --- a/index.html~ +++ b/index.html~ @@ -3,7 +3,7 @@ - + Minecraft.ga - An OP Minecraft Server diff --git a/js/scroll.js b/js/scroll.js new file mode 100644 index 0000000..d929d8c --- /dev/null +++ b/js/scroll.js @@ -0,0 +1,54 @@ +(function() // Code in a function to create an isolate scope +{ +var speed = 500; +var moving_frequency = 15; // Affects performance ! +var links = document.getElementsByTagName('a'); +var href; +for(var i=0; i 1 && href.substr(0, 1) == '#') + { + links[i].onclick = function() + { + var element; + var href = this.attributes.href.nodeValue.toString(); + if(element = document.getElementById(href.substr(1))) + { + var hop_count = speed/moving_frequency + var getScrollTopDocumentAtBegin = getScrollTopDocument(); + var gap = (getScrollTopElement(element) - getScrollTopDocumentAtBegin) / hop_count; + + for(var i = 1; i <= hop_count; i++) + { + (function() + { + var hop_top_position = gap*i; + setTimeout(function(){ window.scrollTo(0, hop_top_position + getScrollTopDocumentAtBegin); }, moving_frequency*i); + })(); + } + } + + return false; + }; + } +} + +var getScrollTopElement = function (e) +{ + var top = 0; + + while (e.offsetParent != undefined && e.offsetParent != null) + { + top += e.offsetTop + (e.clientTop != null ? e.clientTop : 0); + e = e.offsetParent; + } + + return top; +}; + +var getScrollTopDocument = function() +{ + return document.documentElement.scrollTop + document.body.scrollTop; +}; +})(); \ No newline at end of file