@cocreate/scroll 1.5.11 → 1.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +3 -3
- package/.github/workflows/automated.yml +95 -95
- package/.github/workflows/manual.yml +44 -44
- package/CHANGELOG.md +1186 -1171
- package/CONTRIBUTING.md +96 -96
- package/CoCreate.config.js +26 -26
- package/LICENSE +21 -21
- package/README.md +85 -85
- package/demo/index.html +365 -365
- package/docs/index.html +439 -439
- package/package.json +3 -3
- package/release.config.js +21 -21
- package/src/index.js +254 -254
- package/webpack.config.js +84 -84
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/scroll",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.13",
|
|
4
4
|
"description": "A simple scroll component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"scroll",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"webpack-log": "^3.0.1"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@cocreate/docs": "^1.7.
|
|
63
|
-
"@cocreate/observer": "^1.8.
|
|
62
|
+
"@cocreate/docs": "^1.7.15",
|
|
63
|
+
"@cocreate/observer": "^1.8.3"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/release.config.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
dryRun: false,
|
|
3
|
-
branches: ["master"],
|
|
4
|
-
plugins: [
|
|
5
|
-
"@semantic-release/commit-analyzer",
|
|
6
|
-
"@semantic-release/release-notes-generator",
|
|
7
|
-
[
|
|
8
|
-
"@semantic-release/changelog",
|
|
9
|
-
{
|
|
10
|
-
changelogFile: "CHANGELOG.md",
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
"@semantic-release/npm",
|
|
14
|
-
"@semantic-release/github",
|
|
15
|
-
[
|
|
16
|
-
"@semantic-release/git",
|
|
17
|
-
{
|
|
18
|
-
assets: ["CHANGELOG.md", "package.json"],
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
],
|
|
1
|
+
module.exports = {
|
|
2
|
+
dryRun: false,
|
|
3
|
+
branches: ["master"],
|
|
4
|
+
plugins: [
|
|
5
|
+
"@semantic-release/commit-analyzer",
|
|
6
|
+
"@semantic-release/release-notes-generator",
|
|
7
|
+
[
|
|
8
|
+
"@semantic-release/changelog",
|
|
9
|
+
{
|
|
10
|
+
changelogFile: "CHANGELOG.md",
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
"@semantic-release/npm",
|
|
14
|
+
"@semantic-release/github",
|
|
15
|
+
[
|
|
16
|
+
"@semantic-release/git",
|
|
17
|
+
{
|
|
18
|
+
assets: ["CHANGELOG.md", "package.json"],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
],
|
|
22
22
|
};
|
package/src/index.js
CHANGED
|
@@ -1,254 +1,254 @@
|
|
|
1
|
-
import observer from '@cocreate/observer';
|
|
2
|
-
|
|
3
|
-
const CoCreateScroll = {
|
|
4
|
-
delta: 3,
|
|
5
|
-
observer: null,
|
|
6
|
-
timer: null,
|
|
7
|
-
firedEvents: new Map(),
|
|
8
|
-
|
|
9
|
-
init: function() {
|
|
10
|
-
let elements = document.querySelectorAll(`[scroll]`);
|
|
11
|
-
this.__initIntersectionObserver();
|
|
12
|
-
this.initElements(elements);
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
initElements: function(elements) {
|
|
16
|
-
for (let el of elements)
|
|
17
|
-
this.initElement(el);
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
initElement: function(element) {
|
|
21
|
-
const self = this;
|
|
22
|
-
const upSize = this.__getSize(element.getAttribute('scroll-up'));
|
|
23
|
-
const downSize = this.__getSize(element.getAttribute('scroll-down'));
|
|
24
|
-
const attrName = element.getAttribute('scroll-attribute') || 'class';
|
|
25
|
-
const targetSelector = element.getAttribute('scroll-target');
|
|
26
|
-
const scrollSelector = element.getAttribute('scroll-element');
|
|
27
|
-
const intersectValue = element.getAttribute('scroll-intersect');
|
|
28
|
-
|
|
29
|
-
let values = element.getAttribute('scroll') || "";
|
|
30
|
-
values = values.split(",").map(x => x.trim());
|
|
31
|
-
|
|
32
|
-
let scrollInfo = {
|
|
33
|
-
attrName: attrName,
|
|
34
|
-
values: values,
|
|
35
|
-
upSize: upSize,
|
|
36
|
-
downSize: downSize,
|
|
37
|
-
scrollTop: element.getAttribute('scroll-top'),
|
|
38
|
-
scrollLimbo: element.getAttribute('scroll-limbo'),
|
|
39
|
-
scrollBottom: element.getAttribute('scroll-bottom'),
|
|
40
|
-
scrolling: element.getAttribute('scrolling')
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
let elements = [element];
|
|
44
|
-
if (targetSelector) {
|
|
45
|
-
elements = document.querySelectorAll(targetSelector);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
elements.forEach(el => {
|
|
49
|
-
el.scrollStatus = { currentPos: 0 };
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// this.__runScrollEvent(element, scrollInfo);
|
|
53
|
-
|
|
54
|
-
let scrollableElements;
|
|
55
|
-
if (scrollSelector)
|
|
56
|
-
scrollableElements = document.querySelectorAll(scrollSelector);
|
|
57
|
-
|
|
58
|
-
if (scrollableElements) {
|
|
59
|
-
for (let scrollableEl of scrollableElements) {
|
|
60
|
-
scrollableEl.addEventListener('scroll', function(event) {
|
|
61
|
-
self._scrollEvent(elements, element, scrollInfo, scrollableEl)
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
} else{
|
|
65
|
-
// this.WindowInit = true;
|
|
66
|
-
window.addEventListener('scroll', function(event) {
|
|
67
|
-
self._scrollEvent(elements, element, scrollInfo)
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (intersectValue && window.IntersectionObserver && this.observer) {
|
|
72
|
-
this.observer.observe(element);
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
_scrollEvent: function(elements, element, scrollInfo, scrollableEl) {
|
|
77
|
-
const self = this;
|
|
78
|
-
if (!element.scrollStatus) return;
|
|
79
|
-
let scrollEl = scrollableEl || window;
|
|
80
|
-
if (Math.abs(scrollEl.scrollTop || scrollEl.scrollY - element.scrollStatus.currentPos) <= self.delta) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let timer = null;
|
|
85
|
-
if (timer != null) {
|
|
86
|
-
clearTimeout(timer);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
elements.forEach((el) => {
|
|
90
|
-
self.__setScrolling(el, scrollInfo, false);
|
|
91
|
-
self.__runScrollEvent(el, scrollInfo, scrollableEl);
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
timer = setTimeout(function() {
|
|
96
|
-
elements.forEach((el) => {
|
|
97
|
-
self.__setScrolling(el, scrollInfo, true);
|
|
98
|
-
});
|
|
99
|
-
}, 500);
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
__initIntersectionObserver: function() {
|
|
103
|
-
const self = this;
|
|
104
|
-
this.observer = new IntersectionObserver(entries => {
|
|
105
|
-
entries.forEach(entry => {
|
|
106
|
-
let element = entry.target;
|
|
107
|
-
const attrName = element.getAttribute('scroll-attribute') || 'class';
|
|
108
|
-
const targetSelector = element.getAttribute('scroll-target');
|
|
109
|
-
const intersectValue = element.getAttribute('scroll-intersect');
|
|
110
|
-
|
|
111
|
-
let targetElements = [element];
|
|
112
|
-
if (targetSelector) {
|
|
113
|
-
targetElements = document.querySelectorAll(targetSelector);
|
|
114
|
-
}
|
|
115
|
-
if (entry.isIntersecting > 0) {
|
|
116
|
-
targetElements.forEach((el) => self.__addAttributeValue(el, attrName, intersectValue));
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
targetElements.forEach((el) => self.__removeAttrbuteValue(el, attrName, intersectValue));
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
__setScrolling: function(element, info, stopped = false) {
|
|
126
|
-
const { scrolling, attrName } = info;
|
|
127
|
-
if (stopped) {
|
|
128
|
-
this.__removeAttrbuteValue(element, attrName, scrolling);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
this.__addAttributeValue(element, attrName, scrolling);
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
__runScrollEvent: function(element, info, scrollableEl) {
|
|
136
|
-
if (!element.scrollStatus) return
|
|
137
|
-
const currentPos = element.scrollStatus.currentPos;
|
|
138
|
-
let scrollY, scrollHeight, innerHeight;
|
|
139
|
-
if (scrollableEl){
|
|
140
|
-
scrollY = scrollableEl.scrollTop;
|
|
141
|
-
scrollHeight = scrollableEl.scrollHeight
|
|
142
|
-
innerHeight = scrollableEl.clientHeight
|
|
143
|
-
} else {
|
|
144
|
-
scrollY = window.scrollY;
|
|
145
|
-
scrollHeight = document.body.scrollHeight
|
|
146
|
-
innerHeight = window.innerHeight
|
|
147
|
-
}
|
|
148
|
-
const { upSize, downSize, attrName, values, scrollTop, scrollBottom, scrollLimbo } = info;
|
|
149
|
-
|
|
150
|
-
let newTime = new Date().getTime()
|
|
151
|
-
if (!info.datetime || (newTime - info.datetime) > 200 ) {
|
|
152
|
-
info['datetime'] = newTime
|
|
153
|
-
|
|
154
|
-
if (upSize <= (currentPos - scrollY)) {
|
|
155
|
-
this.__addAttributeValue(element, attrName, values[0]);
|
|
156
|
-
this.__removeAttrbuteValue(element, attrName, values[1]);
|
|
157
|
-
}
|
|
158
|
-
else if (downSize <= (scrollY - currentPos)) {
|
|
159
|
-
this.__removeAttrbuteValue(element, attrName, values[0]);
|
|
160
|
-
this.__addAttributeValue(element, attrName, values[1]);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
//. scroll top case
|
|
164
|
-
if (scrollY <= this.delta) {
|
|
165
|
-
this.__removeAttrbuteValue(element, attrName, values[0]);
|
|
166
|
-
this.__removeAttrbuteValue(element, attrName, values[1]);
|
|
167
|
-
|
|
168
|
-
this.__addAttributeValue(element, attrName, scrollTop);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
this.__removeAttrbuteValue(element, attrName, scrollTop);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
//. scroll bottom case
|
|
175
|
-
// if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
|
|
176
|
-
if ((innerHeight + scrollY) >= scrollHeight) {
|
|
177
|
-
// this.__removeAttrbuteValue(element, attrName, values[0]);
|
|
178
|
-
// this.__removeAttrbuteValue(element, attrName, values[1]);
|
|
179
|
-
|
|
180
|
-
this.__addAttributeValue(element, attrName, scrollBottom);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
this.__removeAttrbuteValue(element, attrName, scrollBottom);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
|
|
187
|
-
if (scrollY != 0 && (scrollY + innerHeight) != scrollHeight){
|
|
188
|
-
this.__addAttributeValue(element, attrName, scrollLimbo);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
this.__removeAttrbuteValue(element, attrName, scrollLimbo);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
element.scrollStatus.currentPos = scrollY;
|
|
195
|
-
},
|
|
196
|
-
|
|
197
|
-
__addAttributeValue: function(element, attrName, value) {
|
|
198
|
-
if (!value) return;
|
|
199
|
-
let check = new RegExp("(\\s|^)" + value + "(\\s|$)");
|
|
200
|
-
let attrValue = element.getAttribute(attrName) || "";
|
|
201
|
-
|
|
202
|
-
if (!check.test(attrValue)) {
|
|
203
|
-
attrValue += " " + value;
|
|
204
|
-
element.setAttribute(attrName, attrValue);
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
__removeAttrbuteValue: function(element, attrName, value) {
|
|
209
|
-
if (!value) return;
|
|
210
|
-
let check = new RegExp("(\\s|^)" + value + "(\\s|$)");
|
|
211
|
-
let attrValue = element.getAttribute(attrName) || "";
|
|
212
|
-
|
|
213
|
-
if (check.test(attrValue)) {
|
|
214
|
-
attrValue = attrValue.replace(check, " ").trim();
|
|
215
|
-
element.setAttribute(attrName, attrValue);
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
|
|
219
|
-
__getSize: function(attrValue, isWidth) {
|
|
220
|
-
let size = 0;
|
|
221
|
-
if (!attrValue) {
|
|
222
|
-
return 0;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (attrValue.includes('%')) {
|
|
226
|
-
size = attrValue.replace('%', '').trim();
|
|
227
|
-
size = Number(size) || 0;
|
|
228
|
-
|
|
229
|
-
size = isWidth ? window.innerWidth / size : window.innerHeight / size;
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
size = attrValue.replace('px', '').trim();
|
|
234
|
-
size = Number(size) || 0;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return size;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
observer.init({
|
|
243
|
-
name: 'CoCreateScrollCreate',
|
|
244
|
-
observe: ['addedNodes'],
|
|
245
|
-
target: '[scroll]',
|
|
246
|
-
callback: function(mutation) {
|
|
247
|
-
|
|
248
|
-
CoCreateScroll.initElement(mutation.target);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
CoCreateScroll.init();
|
|
253
|
-
|
|
254
|
-
export default CoCreateScroll;
|
|
1
|
+
import observer from '@cocreate/observer';
|
|
2
|
+
|
|
3
|
+
const CoCreateScroll = {
|
|
4
|
+
delta: 3,
|
|
5
|
+
observer: null,
|
|
6
|
+
timer: null,
|
|
7
|
+
firedEvents: new Map(),
|
|
8
|
+
|
|
9
|
+
init: function() {
|
|
10
|
+
let elements = document.querySelectorAll(`[scroll]`);
|
|
11
|
+
this.__initIntersectionObserver();
|
|
12
|
+
this.initElements(elements);
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
initElements: function(elements) {
|
|
16
|
+
for (let el of elements)
|
|
17
|
+
this.initElement(el);
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
initElement: function(element) {
|
|
21
|
+
const self = this;
|
|
22
|
+
const upSize = this.__getSize(element.getAttribute('scroll-up'));
|
|
23
|
+
const downSize = this.__getSize(element.getAttribute('scroll-down'));
|
|
24
|
+
const attrName = element.getAttribute('scroll-attribute') || 'class';
|
|
25
|
+
const targetSelector = element.getAttribute('scroll-target');
|
|
26
|
+
const scrollSelector = element.getAttribute('scroll-element');
|
|
27
|
+
const intersectValue = element.getAttribute('scroll-intersect');
|
|
28
|
+
|
|
29
|
+
let values = element.getAttribute('scroll') || "";
|
|
30
|
+
values = values.split(",").map(x => x.trim());
|
|
31
|
+
|
|
32
|
+
let scrollInfo = {
|
|
33
|
+
attrName: attrName,
|
|
34
|
+
values: values,
|
|
35
|
+
upSize: upSize,
|
|
36
|
+
downSize: downSize,
|
|
37
|
+
scrollTop: element.getAttribute('scroll-top'),
|
|
38
|
+
scrollLimbo: element.getAttribute('scroll-limbo'),
|
|
39
|
+
scrollBottom: element.getAttribute('scroll-bottom'),
|
|
40
|
+
scrolling: element.getAttribute('scrolling')
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
let elements = [element];
|
|
44
|
+
if (targetSelector) {
|
|
45
|
+
elements = document.querySelectorAll(targetSelector);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
elements.forEach(el => {
|
|
49
|
+
el.scrollStatus = { currentPos: 0 };
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// this.__runScrollEvent(element, scrollInfo);
|
|
53
|
+
|
|
54
|
+
let scrollableElements;
|
|
55
|
+
if (scrollSelector)
|
|
56
|
+
scrollableElements = document.querySelectorAll(scrollSelector);
|
|
57
|
+
|
|
58
|
+
if (scrollableElements) {
|
|
59
|
+
for (let scrollableEl of scrollableElements) {
|
|
60
|
+
scrollableEl.addEventListener('scroll', function(event) {
|
|
61
|
+
self._scrollEvent(elements, element, scrollInfo, scrollableEl)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
} else{
|
|
65
|
+
// this.WindowInit = true;
|
|
66
|
+
window.addEventListener('scroll', function(event) {
|
|
67
|
+
self._scrollEvent(elements, element, scrollInfo)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (intersectValue && window.IntersectionObserver && this.observer) {
|
|
72
|
+
this.observer.observe(element);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
_scrollEvent: function(elements, element, scrollInfo, scrollableEl) {
|
|
77
|
+
const self = this;
|
|
78
|
+
if (!element.scrollStatus) return;
|
|
79
|
+
let scrollEl = scrollableEl || window;
|
|
80
|
+
if (Math.abs(scrollEl.scrollTop || scrollEl.scrollY - element.scrollStatus.currentPos) <= self.delta) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let timer = null;
|
|
85
|
+
if (timer != null) {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
elements.forEach((el) => {
|
|
90
|
+
self.__setScrolling(el, scrollInfo, false);
|
|
91
|
+
self.__runScrollEvent(el, scrollInfo, scrollableEl);
|
|
92
|
+
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
timer = setTimeout(function() {
|
|
96
|
+
elements.forEach((el) => {
|
|
97
|
+
self.__setScrolling(el, scrollInfo, true);
|
|
98
|
+
});
|
|
99
|
+
}, 500);
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
__initIntersectionObserver: function() {
|
|
103
|
+
const self = this;
|
|
104
|
+
this.observer = new IntersectionObserver(entries => {
|
|
105
|
+
entries.forEach(entry => {
|
|
106
|
+
let element = entry.target;
|
|
107
|
+
const attrName = element.getAttribute('scroll-attribute') || 'class';
|
|
108
|
+
const targetSelector = element.getAttribute('scroll-target');
|
|
109
|
+
const intersectValue = element.getAttribute('scroll-intersect');
|
|
110
|
+
|
|
111
|
+
let targetElements = [element];
|
|
112
|
+
if (targetSelector) {
|
|
113
|
+
targetElements = document.querySelectorAll(targetSelector);
|
|
114
|
+
}
|
|
115
|
+
if (entry.isIntersecting > 0) {
|
|
116
|
+
targetElements.forEach((el) => self.__addAttributeValue(el, attrName, intersectValue));
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
targetElements.forEach((el) => self.__removeAttrbuteValue(el, attrName, intersectValue));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
__setScrolling: function(element, info, stopped = false) {
|
|
126
|
+
const { scrolling, attrName } = info;
|
|
127
|
+
if (stopped) {
|
|
128
|
+
this.__removeAttrbuteValue(element, attrName, scrolling);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.__addAttributeValue(element, attrName, scrolling);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
__runScrollEvent: function(element, info, scrollableEl) {
|
|
136
|
+
if (!element.scrollStatus) return
|
|
137
|
+
const currentPos = element.scrollStatus.currentPos;
|
|
138
|
+
let scrollY, scrollHeight, innerHeight;
|
|
139
|
+
if (scrollableEl){
|
|
140
|
+
scrollY = scrollableEl.scrollTop;
|
|
141
|
+
scrollHeight = scrollableEl.scrollHeight
|
|
142
|
+
innerHeight = scrollableEl.clientHeight
|
|
143
|
+
} else {
|
|
144
|
+
scrollY = window.scrollY;
|
|
145
|
+
scrollHeight = document.body.scrollHeight
|
|
146
|
+
innerHeight = window.innerHeight
|
|
147
|
+
}
|
|
148
|
+
const { upSize, downSize, attrName, values, scrollTop, scrollBottom, scrollLimbo } = info;
|
|
149
|
+
|
|
150
|
+
let newTime = new Date().getTime()
|
|
151
|
+
if (!info.datetime || (newTime - info.datetime) > 200 ) {
|
|
152
|
+
info['datetime'] = newTime
|
|
153
|
+
|
|
154
|
+
if (upSize <= (currentPos - scrollY)) {
|
|
155
|
+
this.__addAttributeValue(element, attrName, values[0]);
|
|
156
|
+
this.__removeAttrbuteValue(element, attrName, values[1]);
|
|
157
|
+
}
|
|
158
|
+
else if (downSize <= (scrollY - currentPos)) {
|
|
159
|
+
this.__removeAttrbuteValue(element, attrName, values[0]);
|
|
160
|
+
this.__addAttributeValue(element, attrName, values[1]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//. scroll top case
|
|
164
|
+
if (scrollY <= this.delta) {
|
|
165
|
+
this.__removeAttrbuteValue(element, attrName, values[0]);
|
|
166
|
+
this.__removeAttrbuteValue(element, attrName, values[1]);
|
|
167
|
+
|
|
168
|
+
this.__addAttributeValue(element, attrName, scrollTop);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.__removeAttrbuteValue(element, attrName, scrollTop);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//. scroll bottom case
|
|
175
|
+
// if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
|
|
176
|
+
if ((innerHeight + scrollY) >= scrollHeight) {
|
|
177
|
+
// this.__removeAttrbuteValue(element, attrName, values[0]);
|
|
178
|
+
// this.__removeAttrbuteValue(element, attrName, values[1]);
|
|
179
|
+
|
|
180
|
+
this.__addAttributeValue(element, attrName, scrollBottom);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
this.__removeAttrbuteValue(element, attrName, scrollBottom);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
|
|
187
|
+
if (scrollY != 0 && (scrollY + innerHeight) != scrollHeight){
|
|
188
|
+
this.__addAttributeValue(element, attrName, scrollLimbo);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
this.__removeAttrbuteValue(element, attrName, scrollLimbo);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
element.scrollStatus.currentPos = scrollY;
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
__addAttributeValue: function(element, attrName, value) {
|
|
198
|
+
if (!value) return;
|
|
199
|
+
let check = new RegExp("(\\s|^)" + value + "(\\s|$)");
|
|
200
|
+
let attrValue = element.getAttribute(attrName) || "";
|
|
201
|
+
|
|
202
|
+
if (!check.test(attrValue)) {
|
|
203
|
+
attrValue += " " + value;
|
|
204
|
+
element.setAttribute(attrName, attrValue);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
__removeAttrbuteValue: function(element, attrName, value) {
|
|
209
|
+
if (!value) return;
|
|
210
|
+
let check = new RegExp("(\\s|^)" + value + "(\\s|$)");
|
|
211
|
+
let attrValue = element.getAttribute(attrName) || "";
|
|
212
|
+
|
|
213
|
+
if (check.test(attrValue)) {
|
|
214
|
+
attrValue = attrValue.replace(check, " ").trim();
|
|
215
|
+
element.setAttribute(attrName, attrValue);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
__getSize: function(attrValue, isWidth) {
|
|
220
|
+
let size = 0;
|
|
221
|
+
if (!attrValue) {
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (attrValue.includes('%')) {
|
|
226
|
+
size = attrValue.replace('%', '').trim();
|
|
227
|
+
size = Number(size) || 0;
|
|
228
|
+
|
|
229
|
+
size = isWidth ? window.innerWidth / size : window.innerHeight / size;
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
size = attrValue.replace('px', '').trim();
|
|
234
|
+
size = Number(size) || 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return size;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
observer.init({
|
|
243
|
+
name: 'CoCreateScrollCreate',
|
|
244
|
+
observe: ['addedNodes'],
|
|
245
|
+
target: '[scroll]',
|
|
246
|
+
callback: function(mutation) {
|
|
247
|
+
|
|
248
|
+
CoCreateScroll.initElement(mutation.target);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
CoCreateScroll.init();
|
|
253
|
+
|
|
254
|
+
export default CoCreateScroll;
|