-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
144 lines (142 loc) · 4 KB
/
index.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
function Fadeout() { }
function animationclass(name) {
//渐出
}
//加载资源方法
function loadStyle(url) {
const link = document.createElement('link')
link.type = 'text/css'
link.rel = 'stylesheet'
link.href = url
const head = document.getElementsByTagName('head')[0]
head.appendChild(link)
}
function loadscript(url) {
const link = document.createElement('script')
link.src = url
const head = document.getElementsByTagName('body')[0]
head.appendChild(link)
}
//监听dom
function FadeIntersectionObserver(cnodes, styleall) {
let io = new IntersectionObserver((e) => {
e.map(item => {
if (item.isIntersecting) {
let nodeMap = {
style: cnodes.getAttribute('style'),
};
//动画时间
cnodes.setAttribute('style', `opacity: 0;
${animatorientation(styleall.orientation,1000)} ${nodeMap.style}`)
setTimeout(res => {
cnodes.setAttribute('style', `opacity: 1;
${animatorientation(styleall.orientation,0,true)} transition:${styleall.time}ms all;${nodeMap.style} `)
}, 100)
}
})
}, {});
io.observe(cnodes);
}
//方位定向
function animatorientation(direction, px, istwo) {
switch (direction) {
case 'left':
if (istwo) {
return `transform: translateX(0px);`
}
return `transform: translateX(-10vw);`
break;
case 'top':
if (istwo) {
return `transform: translateY(0px);`
}
return `transform: translateY(-10vh);`
break;
case 'bottom':
if (istwo) {
return `transform: translateY(0px);`
}
return `transform: translateY(10vh);`
break;
case 'right':
if (istwo) {
return `transform: translateX(0px);`
}
return `transform: translateX(10vw);`
break;
default:
}
}
// 递归函数
function openNodes(node) {
// 判断是否存在子节点
if (node.hasChildNodes()) {
// 获取子节点
let cnodes = node.childNodes;
// 对子节点进行递归处理
for (let i = 0; i < cnodes.length; i++) {
resultisbot(cnodes[i])
reviewnode(cnodes[i])
}
}
}
//检索dom节点下是否存在标识属性
function reviewnode(cnodes) {
if (cnodes) {
let cnodesnext = cnodes.childNodes;
for (let reviewnodeitem = 0; reviewnodeitem < cnodes.childNodes.length; reviewnodeitem++) {
resultisbot(cnodesnext[reviewnodeitem])
reviewnode(cnodesnext[reviewnodeitem])
}
}
}
//属性检索
function Attributesearch(cnodes) {
if (cnodes.getAttribute('free')) {
const keylength = cnodes.getAttribute('free').split('-');
const Setstyle = {
types: "",
subclass: "",
orientation: '',
time: 1000
};
keylength.map((itme, index) => {
switch (index) {
case 0:
Setstyle.types = itme;
break;
case 1:
Setstyle.subclass = itme;
break;
case 2:
Setstyle.orientation = itme;
break;
case 3:
Setstyle.time = itme;
break;
default:
}
})
FadeIntersectionObserver(cnodes, Setstyle);
}
}
//检索载入
function resultisbot(cnodes) {
try {
if (cnodes) {
if (cnodes.attributes) {
Attributesearch(cnodes);
}
}
}
catch (err) {
console.error(err.message);
}
}
//初始化
function resultinit() {
openNodes(document.body)
}
if (document.body && document.body.getElementsByTagName) {
resultinit();
}