-
Notifications
You must be signed in to change notification settings - Fork 28
/
all.js
71 lines (66 loc) · 1.97 KB
/
all.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
addLoadEvent(toTopSpan);
addLoadEvent(imgSlider);
window.onscroll = function () {
var navbarEle = document.getElementById("navbar");
var toTopEle = document.getElementById("toTop");
var navbarOffset = navbarEle.offsetTop;
var parentOffset = navbarEle.offsetParent;
if (parentOffset !== null) {
navbarOffset += parentOffset.offsetTop;
parentOffset = parentOffset.offsetParent;
}
var navbarScroll = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
if (navbarScroll - navbarOffset > 30) {
navbarEle.className = "fixed";
} else {
navbarEle.className = "";
}
if (navbarScroll > 1000) {
toTopEle.style.visibility = "visible";
toTopEle.style.pointerEvents = "auto";
} else {
toTopEle.style.visibility = "hidden";
toTopEle.style.pointerEvents = "none";
}
};
function toTopSpan() {
var toTopF = document.getElementById("toTop");
toTopF.onclick = function () {
window.scrollTo(0, 0);
};
}
function imgSlider() {
var slides = document.getElementsByClassName("slides");
var maskWidth = 648;
Array.prototype.forEach.call(slides, function (el, i) {
el.style.left = (i * maskWidth) + "px";
});
window.preNext = function (x) {
var widthCounter = maskWidth;
if ((x == 'imgnext' && (parseInt(slides[0].style.left) + maskWidth * (slides.length - 1) > 0)) || (x == 'imgpre' && (parseInt(slides[0].style.left) < 0))) {
var slideWithdraw = setInterval(function () {
var moveSpeed = 4;
Array.prototype.forEach.call(slides, function (el, i) {
if (widthCounter <= 0) {
clearInterval(slideWithdraw);
} else {
el.style.left = (x == 'imgnext') ? (parseInt(el.style.left) - moveSpeed) + "px" : (parseInt(el.style.left) + moveSpeed) + "px";
}
});
widthCounter -= moveSpeed;
}, 1);
}
};
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != "function") {
window.onload = func;
}
else {
window.onload = function () {
oldonload();
func();
};
}
}