@pushword/js-helper 0.0.104 → 0.0.106
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 +41 -21
package/package.json
CHANGED
package/src/ScrollEnhancer.js
CHANGED
|
@@ -26,20 +26,32 @@ class ScrollYEnhancer {
|
|
|
26
26
|
|
|
27
27
|
wheelScroll(element) {
|
|
28
28
|
element.addEventListener('wheel', (evt) => {
|
|
29
|
+
if (window.isScrolling === true) return
|
|
29
30
|
evt.preventDefault()
|
|
30
|
-
|
|
31
|
+
window.isScrolling = true
|
|
32
|
+
|
|
31
33
|
const before = element.scrollTop
|
|
32
34
|
element.scrollTop += evt.deltaY
|
|
33
|
-
|
|
34
|
-
if (before ===
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
|
|
36
|
+
if (before === element.scrollTop) {
|
|
37
|
+
if (
|
|
38
|
+
(parent = element.closest('.enhance-scroll-x')) &&
|
|
39
|
+
new Date().getTime() - window.lastScrollTime > 200 &&
|
|
40
|
+
scrollX(parent.parentNode.querySelector(evt.deltaY > 0 ? '.scroll-right' : '.scroll-left'))
|
|
41
|
+
) {
|
|
42
|
+
window.lastScrollTime = new Date().getTime()
|
|
43
|
+
window.isScrolling = false
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (new Date().getTime() - window.lastScrollTime > 200) {
|
|
48
|
+
window.lastScrollTime = new Date().getTime()
|
|
49
|
+
const toScrollHeight = element.dataset.toscroll ?? 600
|
|
50
|
+
window.scrollBy({ top: evt.deltaY > 0 ? toScrollHeight : -toScrollHeight, left: 0, behavior: 'smooth' })
|
|
51
|
+
}
|
|
52
|
+
} else window.lastScrollTime = new Date().getTime()
|
|
53
|
+
window.isScrolling = false
|
|
41
54
|
})
|
|
42
|
-
return this
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
enhanceScrollY(element) {
|
|
@@ -132,20 +144,26 @@ class ScrollXEnhancer {
|
|
|
132
144
|
|
|
133
145
|
wheelScroll(element) {
|
|
134
146
|
element.addEventListener('wheel', (evt) => {
|
|
135
|
-
evt.preventDefault()
|
|
136
|
-
if (evt.target.closest('.enhance-scroll-y')) return
|
|
137
147
|
if (window.isScrolling === true) return
|
|
138
|
-
|
|
148
|
+
evt.preventDefault()
|
|
149
|
+
window.isScrolling = true
|
|
150
|
+
|
|
151
|
+
if (evt.target.closest('.enhance-scroll-y')) {
|
|
152
|
+
window.isScrolling = false
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
|
|
139
156
|
const before = element.scrollLeft
|
|
140
157
|
element.scrollLeft += evt.deltaY
|
|
141
|
-
|
|
142
|
-
if (before ===
|
|
143
|
-
window.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
158
|
+
|
|
159
|
+
if (before === element.scrollLeft) {
|
|
160
|
+
if (new Date().getTime() - window.lastScrollTime > 200) {
|
|
161
|
+
window.lastScrollTime = new Date().getTime()
|
|
162
|
+
const toScrollHeight = element.dataset.toscroll ?? 600
|
|
163
|
+
window.scrollBy({ top: evt.deltaY > 0 ? toScrollHeight : -toScrollHeight, left: 0, behavior: 'smooth' })
|
|
164
|
+
}
|
|
165
|
+
} else window.lastScrollTime = new Date().getTime()
|
|
166
|
+
window.isScrolling = false
|
|
149
167
|
})
|
|
150
168
|
}
|
|
151
169
|
|
|
@@ -165,7 +183,9 @@ class ScrollXEnhancer {
|
|
|
165
183
|
|
|
166
184
|
const nextElementToScroll = element.children[3] // work only with equal width block
|
|
167
185
|
const toScrollWidth = nextElementToScroll.offsetWidth + parseInt(window.getComputedStyle(nextElementToScroll).marginLeft)
|
|
186
|
+
const before = element.scrollLeft
|
|
168
187
|
element.scrollLeft += scrollToRight ? toScrollWidth : -toScrollWidth
|
|
188
|
+
return before !== element.scrollLeft
|
|
169
189
|
}
|
|
170
190
|
|
|
171
191
|
manageScrollXControllerVisibility(element) {
|