@pushword/js-helper 0.0.108 → 0.0.110
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/package.json +1 -1
- package/src/ScrollEnhancer.js +20 -6
package/package.json
CHANGED
package/src/ScrollEnhancer.js
CHANGED
|
@@ -7,12 +7,17 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
class ScrollYEnhancer {
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(
|
|
11
|
+
selector = '.enhance-scroll-y',
|
|
12
|
+
arrow = '<div class="scroller absolute left-[128px] z-10 -mt-[10px] h-[36px] w-[36px] cursor-pointer rounded-full border border-gray-200 bg-white text-center text-3xl leading-[23px] text-gray-500 hover:text-gray-700 select-none" onclick="scrollPreviousDiv(this)">⌄</div><div class="relative z-0 -mt-8 h-8 w-full bg-gradient-to-t from-white to-transparent"></div>',
|
|
13
|
+
fadeout = '<div class="sticky left-0 -top-3 z-0 -mt-3 h-3 w-full bg-gradient-to-b from-white to-transparent"></div>',
|
|
14
|
+
) {
|
|
11
15
|
window.scrollPreviousDiv = this.scrollPreviousDiv
|
|
12
16
|
window.manageScrollYControllerVisibility = this.manageScrollYControllerVisibility
|
|
17
|
+
window.isScrolling = false
|
|
13
18
|
|
|
14
19
|
document.querySelectorAll(selector).forEach((element) => {
|
|
15
|
-
if (element.scrollHeight <= element.clientHeight
|
|
20
|
+
if (element.scrollHeight <= element.clientHeight + 20) {
|
|
16
21
|
// 20 = padding-bottom
|
|
17
22
|
element.classList.remove('enhance-scroll-y')
|
|
18
23
|
return
|
|
@@ -40,7 +45,11 @@ class ScrollYEnhancer {
|
|
|
40
45
|
element.scrollTop += evt.deltaY
|
|
41
46
|
|
|
42
47
|
if (before === element.scrollTop) {
|
|
43
|
-
if (
|
|
48
|
+
if (
|
|
49
|
+
(parent = element.closest('.enhance-scroll-x')) &&
|
|
50
|
+
new Date().getTime() - window.lastScrollTime > 200 &&
|
|
51
|
+
scrollX(parent.parentNode.querySelector(evt.deltaY > 0 ? '.scroll-right' : '.scroll-left'))
|
|
52
|
+
) {
|
|
44
53
|
window.lastScrollTime = new Date().getTime()
|
|
45
54
|
window.isScrolling = false
|
|
46
55
|
return
|
|
@@ -122,13 +131,18 @@ class ScrollYEnhancer {
|
|
|
122
131
|
}
|
|
123
132
|
|
|
124
133
|
class ScrollXEnhancer {
|
|
125
|
-
constructor(
|
|
134
|
+
constructor(
|
|
135
|
+
selector = '.enhance-scroll-x',
|
|
136
|
+
arrowRight = '<div class="scroll-right relative left-[calc(100vw-62px)] -mt-[36px] top-1/3 z-20 h-[36px] w-[36px] cursor-pointer select-none rounded-full border border-gray-200 bg-white text-center text-3xl leading-none text-gray-500 hover:text-gray-700" onclick="scrollX(this)">›</div>',
|
|
137
|
+
arrowLeft = '<div class="scroll-left relative left-[22px] top-1/3 z-20 h-[36px] w-[36px] cursor-pointer select-none rounded-full border border-gray-200 bg-white text-center text-3xl leading-none text-gray-500 hover:text-gray-700" onclick="scrollX(this)">‹</div>',
|
|
138
|
+
) {
|
|
126
139
|
window.scrollLeft = this.scrollLeft
|
|
127
140
|
window.scrollX = this.scrollX
|
|
128
141
|
window.manageScrollXControllerVisibility = this.manageScrollXControllerVisibility
|
|
142
|
+
window.isScrolling = false
|
|
129
143
|
|
|
130
144
|
document.querySelectorAll(selector).forEach((element) => {
|
|
131
|
-
if (element.scrollWidth <= element.clientWidth
|
|
145
|
+
if (element.scrollWidth <= element.clientWidth + 12) {
|
|
132
146
|
// 20 = padding-bottom
|
|
133
147
|
element.classList.remove('enhance-scroll-x')
|
|
134
148
|
return
|
|
@@ -177,6 +191,7 @@ class ScrollXEnhancer {
|
|
|
177
191
|
}
|
|
178
192
|
|
|
179
193
|
scrollX(scroller, selector = '.enhance-scroll-x') {
|
|
194
|
+
if (!scroller) return
|
|
180
195
|
const element = scroller.parentNode.querySelector(selector)
|
|
181
196
|
if (!element) return
|
|
182
197
|
|
|
@@ -229,7 +244,6 @@ class ScrollXEnhancer {
|
|
|
229
244
|
}
|
|
230
245
|
}
|
|
231
246
|
|
|
232
|
-
|
|
233
247
|
module.exports = {
|
|
234
248
|
ScrollXEnhancer: ScrollXEnhancer,
|
|
235
249
|
ScrollYEnhancer: ScrollYEnhancer,
|