mirror of
https://github.com/kaboomserver/website.git
synced 2024-11-29 10:46:00 -05:00
Initial Commit
This commit is contained in:
parent
19ac23fd53
commit
4136f33f8b
2 changed files with 55 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
(function() // Code in a function to create an isolate scope
|
(function() // Code in a function to create an isolate scope
|
||||||
{
|
{
|
||||||
var speed = 500;
|
var speed = 500;
|
||||||
var moving_frequency = 15; // Affects performance !
|
var moving_frequency = 35; // Affects performance !
|
||||||
var links = document.getElementsByTagName('a');
|
var links = document.getElementsByTagName('a');
|
||||||
var href;
|
var href;
|
||||||
for(var i=0; i<links.length; i++)
|
for(var i=0; i<links.length; i++)
|
||||||
|
|
54
js/scroll.js~
Normal file
54
js/scroll.js~
Normal file
|
@ -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<links.length; i++)
|
||||||
|
{
|
||||||
|
href = (links[i].attributes.href === undefined) ? null : links[i].attributes.href.nodeValue.toString();
|
||||||
|
if(href !== null && href.length > 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;
|
||||||
|
};
|
||||||
|
})();
|
Loading…
Reference in a new issue