@pushword/js-helper 0.0.107 → 0.0.109
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 +24 -8
- package/src/tailwind.prose.scss +0 -1
package/package.json
CHANGED
package/src/ScrollEnhancer.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Demo in Draft
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Demo in Draft
|
|
7
|
+
*/
|
|
8
|
+
|
|
5
9
|
class ScrollYEnhancer {
|
|
6
10
|
constructor(
|
|
7
11
|
selector = '.enhance-scroll-y',
|
|
@@ -10,21 +14,28 @@ class ScrollYEnhancer {
|
|
|
10
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) => {
|
|
20
|
+
if (element.scrollHeight <= element.clientHeight - 20) {
|
|
21
|
+
// 20 = padding-bottom
|
|
22
|
+
element.classList.remove('enhance-scroll-y')
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
this.arrow = element.dataset.arrow ?? arrow
|
|
16
27
|
this.fadeout = element.dataset.fadeout ?? fadeout
|
|
17
28
|
element.classList.remove(selector)
|
|
18
29
|
this.enhanceScrollY(element)
|
|
19
30
|
this.mouseSliderY(element)
|
|
20
|
-
this.
|
|
31
|
+
this.wheelScrollY(element)
|
|
21
32
|
element.onscroll = function () {
|
|
22
33
|
manageScrollYControllerVisibility(this)
|
|
23
34
|
}
|
|
24
35
|
})
|
|
25
36
|
}
|
|
26
37
|
|
|
27
|
-
|
|
38
|
+
wheelScrollY(element) {
|
|
28
39
|
element.addEventListener('wheel', (evt) => {
|
|
29
40
|
if (window.isScrolling === true) return
|
|
30
41
|
evt.preventDefault()
|
|
@@ -72,7 +83,7 @@ class ScrollYEnhancer {
|
|
|
72
83
|
|
|
73
84
|
manageScrollYControllerVisibility(element) {
|
|
74
85
|
const scroller = element.parentNode.querySelector('.scroller')
|
|
75
|
-
const isAtMaxScroll = element.scrollTop >= element.scrollHeight - element.clientHeight -
|
|
86
|
+
const isAtMaxScroll = element.scrollTop >= element.scrollHeight - element.clientHeight - 8
|
|
76
87
|
if (scroller.textContent === '⌄' || isAtMaxScroll) {
|
|
77
88
|
if (isAtMaxScroll) {
|
|
78
89
|
scroller.textContent = '⌃'
|
|
@@ -128,21 +139,28 @@ class ScrollXEnhancer {
|
|
|
128
139
|
window.scrollLeft = this.scrollLeft
|
|
129
140
|
window.scrollX = this.scrollX
|
|
130
141
|
window.manageScrollXControllerVisibility = this.manageScrollXControllerVisibility
|
|
142
|
+
window.isScrolling = false
|
|
131
143
|
|
|
132
144
|
document.querySelectorAll(selector).forEach((element) => {
|
|
145
|
+
if (element.scrollWidth <= element.clientWidth - 12) {
|
|
146
|
+
// 20 = padding-bottom
|
|
147
|
+
element.classList.remove('enhance-scroll-x')
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
133
151
|
this.arrowLeft = element.dataset.arrowleft ?? arrowLeft
|
|
134
152
|
this.arrowRight = element.dataset.arrowright ?? arrowRight
|
|
135
153
|
element.classList.remove(selector)
|
|
136
154
|
this.enhanceScrollX(element)
|
|
137
155
|
this.mouseSliderX(element)
|
|
138
|
-
this.
|
|
156
|
+
this.wheelScrollX(element)
|
|
139
157
|
element.onscroll = function () {
|
|
140
158
|
manageScrollXControllerVisibility(this)
|
|
141
159
|
}
|
|
142
160
|
})
|
|
143
161
|
}
|
|
144
162
|
|
|
145
|
-
|
|
163
|
+
wheelScrollX(element) {
|
|
146
164
|
element.addEventListener('wheel', (evt) => {
|
|
147
165
|
if (window.isScrolling === true) return
|
|
148
166
|
evt.preventDefault()
|
|
@@ -173,14 +191,12 @@ class ScrollXEnhancer {
|
|
|
173
191
|
}
|
|
174
192
|
|
|
175
193
|
scrollX(scroller, selector = '.enhance-scroll-x') {
|
|
194
|
+
if (!scroller) return
|
|
176
195
|
const element = scroller.parentNode.querySelector(selector)
|
|
177
196
|
if (!element) return
|
|
178
197
|
|
|
179
198
|
const scrollToRight = scroller.classList.contains('scroll-right')
|
|
180
199
|
|
|
181
|
-
const oppositeSelector = scrollToRight ? 'scroll-left' : 'scroll-right'
|
|
182
|
-
const oppositeController = element.querySelector('.' + oppositeSelector)
|
|
183
|
-
|
|
184
200
|
const nextElementToScroll = element.children[3] // work only with equal width block
|
|
185
201
|
const toScrollWidth = nextElementToScroll.offsetWidth + parseInt(window.getComputedStyle(nextElementToScroll).marginLeft)
|
|
186
202
|
const before = element.scrollLeft
|