-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (37 loc) · 1.24 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function setListener(element) {
element.addEventListener('click', function (event) {
scroll(element);
event.preventDefault();
});
}
function scroll(element) {
var to = document.getElementById(element.getAttribute("href").substring(1, element.getAttribute("href").length)).offsetTop;
var duration = 400;
doScroll(element, to, duration);
}
function doScroll(element, to, duration) {
console.log("HEY");
if (duration <= 0) return;
var difference = to - document.body.scrollTop;
var perTick = difference / duration * 10;
setTimeout(function() {
document.body.scrollTop = document.body.scrollTop + perTick;
if (document.body.scrollTop == to) return;
doScroll(element, to, duration - 10);
}, 10);
}
window.onload = function () {
var elems = document.getElementsByTagName("a");
for (var i = 0; i < elems.length; i++) {
if (elems[i].hasAttribute("anchor")) {
if (elems[i].getAttribute("anchor")) setListener(elems[i]);
}
}
var lazyboys = document.getElementsByClassName("lazyloaded");
for (var i = 0; i < lazyboys.length; i++) {
lazyboys[i].setAttribute('src', lazyboys[i].getAttribute('data-src'));
lazyboys[i].onload = function() {
lazyboys[i].removeAttribute('data-src');
};
};
};