@pushword/js-helper 0.0.106 → 0.0.108
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 +27 -25
- package/src/tailwind.prose.scss +0 -1
package/package.json
CHANGED
package/src/ScrollEnhancer.js
CHANGED
|
@@ -2,29 +2,35 @@
|
|
|
2
2
|
* Demo in Draft
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Demo in Draft
|
|
7
|
+
*/
|
|
8
|
+
|
|
5
9
|
class ScrollYEnhancer {
|
|
6
|
-
constructor(
|
|
7
|
-
selector = '.enhance-scroll-y',
|
|
8
|
-
arrow = '<div class="scroller absolute left-[128px] z-10 -mt-[10px] h-[44px] w-[44px] cursor-pointer rounded-full border border-gray-200 bg-white text-center text-3xl leading-none 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>',
|
|
9
|
-
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>',
|
|
10
|
-
) {
|
|
10
|
+
constructor(selector = '.enhance-scroll-y', 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>', 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>') {
|
|
11
11
|
window.scrollPreviousDiv = this.scrollPreviousDiv
|
|
12
12
|
window.manageScrollYControllerVisibility = this.manageScrollYControllerVisibility
|
|
13
13
|
|
|
14
14
|
document.querySelectorAll(selector).forEach((element) => {
|
|
15
|
+
if (element.scrollHeight <= element.clientHeight - 20) {
|
|
16
|
+
// 20 = padding-bottom
|
|
17
|
+
element.classList.remove('enhance-scroll-y')
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
this.arrow = element.dataset.arrow ?? arrow
|
|
16
22
|
this.fadeout = element.dataset.fadeout ?? fadeout
|
|
17
23
|
element.classList.remove(selector)
|
|
18
24
|
this.enhanceScrollY(element)
|
|
19
25
|
this.mouseSliderY(element)
|
|
20
|
-
this.
|
|
26
|
+
this.wheelScrollY(element)
|
|
21
27
|
element.onscroll = function () {
|
|
22
28
|
manageScrollYControllerVisibility(this)
|
|
23
29
|
}
|
|
24
30
|
})
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
wheelScrollY(element) {
|
|
28
34
|
element.addEventListener('wheel', (evt) => {
|
|
29
35
|
if (window.isScrolling === true) return
|
|
30
36
|
evt.preventDefault()
|
|
@@ -34,11 +40,7 @@ class ScrollYEnhancer {
|
|
|
34
40
|
element.scrollTop += evt.deltaY
|
|
35
41
|
|
|
36
42
|
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
|
-
) {
|
|
43
|
+
if ((parent = element.closest('.enhance-scroll-x')) && new Date().getTime() - window.lastScrollTime > 200 && scrollX(parent.parentNode.querySelector(evt.deltaY > 0 ? '.scroll-right' : '.scroll-left'))) {
|
|
42
44
|
window.lastScrollTime = new Date().getTime()
|
|
43
45
|
window.isScrolling = false
|
|
44
46
|
return
|
|
@@ -72,17 +74,17 @@ class ScrollYEnhancer {
|
|
|
72
74
|
|
|
73
75
|
manageScrollYControllerVisibility(element) {
|
|
74
76
|
const scroller = element.parentNode.querySelector('.scroller')
|
|
75
|
-
const isAtMaxScroll = element.scrollTop >= element.scrollHeight - element.clientHeight -
|
|
77
|
+
const isAtMaxScroll = element.scrollTop >= element.scrollHeight - element.clientHeight - 8
|
|
76
78
|
if (scroller.textContent === '⌄' || isAtMaxScroll) {
|
|
77
79
|
if (isAtMaxScroll) {
|
|
78
80
|
scroller.textContent = '⌃'
|
|
79
|
-
scroller.classList.add('pt-[
|
|
81
|
+
scroller.classList.add('pt-[12px]')
|
|
80
82
|
scroller.classList.add('text-gray-200')
|
|
81
83
|
}
|
|
82
84
|
return
|
|
83
85
|
} else {
|
|
84
86
|
scroller.textContent = '⌄'
|
|
85
|
-
scroller.classList.remove('pt-[
|
|
87
|
+
scroller.classList.remove('pt-[12px]')
|
|
86
88
|
scroller.classList.remove('text-gray-200')
|
|
87
89
|
}
|
|
88
90
|
}
|
|
@@ -120,29 +122,31 @@ class ScrollYEnhancer {
|
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
class ScrollXEnhancer {
|
|
123
|
-
constructor(
|
|
124
|
-
selector = '.enhance-scroll-x',
|
|
125
|
-
arrowRight = '<div class="scroll-right relative left-[calc(100vw-62px)] -mt-[44px] top-1/3 z-20 h-[44px] w-[44px] cursor-pointer select-none rounded-full border border-gray-200 bg-white pt-[3px] text-center text-3xl leading-none text-gray-500 hover:text-gray-700" onclick="scrollX(this)">›</div>',
|
|
126
|
-
arrowLeft = '<div class="scroll-left relative left-[22px] top-1/3 z-20 h-[44px] w-[44px] cursor-pointer select-none rounded-full border border-gray-200 bg-white pt-[3px] text-center text-3xl leading-none text-gray-500 hover:text-gray-700" onclick="scrollX(this)">‹</div>',
|
|
127
|
-
) {
|
|
125
|
+
constructor(selector = '.enhance-scroll-x', 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>', 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>') {
|
|
128
126
|
window.scrollLeft = this.scrollLeft
|
|
129
127
|
window.scrollX = this.scrollX
|
|
130
128
|
window.manageScrollXControllerVisibility = this.manageScrollXControllerVisibility
|
|
131
129
|
|
|
132
130
|
document.querySelectorAll(selector).forEach((element) => {
|
|
131
|
+
if (element.scrollWidth <= element.clientWidth - 12) {
|
|
132
|
+
// 20 = padding-bottom
|
|
133
|
+
element.classList.remove('enhance-scroll-x')
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
133
137
|
this.arrowLeft = element.dataset.arrowleft ?? arrowLeft
|
|
134
138
|
this.arrowRight = element.dataset.arrowright ?? arrowRight
|
|
135
139
|
element.classList.remove(selector)
|
|
136
140
|
this.enhanceScrollX(element)
|
|
137
141
|
this.mouseSliderX(element)
|
|
138
|
-
this.
|
|
142
|
+
this.wheelScrollX(element)
|
|
139
143
|
element.onscroll = function () {
|
|
140
144
|
manageScrollXControllerVisibility(this)
|
|
141
145
|
}
|
|
142
146
|
})
|
|
143
147
|
}
|
|
144
148
|
|
|
145
|
-
|
|
149
|
+
wheelScrollX(element) {
|
|
146
150
|
element.addEventListener('wheel', (evt) => {
|
|
147
151
|
if (window.isScrolling === true) return
|
|
148
152
|
evt.preventDefault()
|
|
@@ -178,9 +182,6 @@ class ScrollXEnhancer {
|
|
|
178
182
|
|
|
179
183
|
const scrollToRight = scroller.classList.contains('scroll-right')
|
|
180
184
|
|
|
181
|
-
const oppositeSelector = scrollToRight ? 'scroll-left' : 'scroll-right'
|
|
182
|
-
const oppositeController = element.querySelector('.' + oppositeSelector)
|
|
183
|
-
|
|
184
185
|
const nextElementToScroll = element.children[3] // work only with equal width block
|
|
185
186
|
const toScrollWidth = nextElementToScroll.offsetWidth + parseInt(window.getComputedStyle(nextElementToScroll).marginLeft)
|
|
186
187
|
const before = element.scrollLeft
|
|
@@ -228,6 +229,7 @@ class ScrollXEnhancer {
|
|
|
228
229
|
}
|
|
229
230
|
}
|
|
230
231
|
|
|
232
|
+
|
|
231
233
|
module.exports = {
|
|
232
234
|
ScrollXEnhancer: ScrollXEnhancer,
|
|
233
235
|
ScrollYEnhancer: ScrollYEnhancer,
|