MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / touchMove

Function touchMove

src/components/scrollbar/index.js:135–169  ·  view source on GitHub ↗

* * @param {TouchEvent | MouseEvent} e

(e)

Source from the content-addressed store, hash-verified

133 * @param {TouchEvent | MouseEvent} e
134 */
135 function touchMove(e) {
136 const touch = e.type === "touchmove" ? e.touches[0] : e;
137 const touchDiffX = touchStartValue.x - touch.clientX;
138 const touchDiffY = touchStartValue.y - touch.clientY;
139 touchStartValue.x = touch.clientX;
140 touchStartValue.y = touch.clientY;
141
142 if (isVertical) {
143 let top = Number.parseFloat($cursor.style.top) - touchDiffY;
144 const currentTopValue = Number.parseFloat($cursor.style.top);
145
146 if (top < 0) top = 0;
147 else if (top > height) top = height;
148
149 if (currentTopValue !== top) {
150 $cursor.style.top = top + "px";
151 scroll = top / height;
152 if (typeof $scrollbar.onScroll === "function")
153 $scrollbar.onScroll(scroll);
154 }
155 } else {
156 let left = Number.parseFloat($cursor.style.left) - touchDiffX;
157 const currentLeftValue = Number.parseFloat($cursor.style.left);
158
159 if (left < 0) left = 0;
160 else if (left > width) left = width;
161
162 if (currentLeftValue !== left) {
163 $cursor.style.left = left + "px";
164 scroll = left / width;
165 if (typeof $scrollbar.onScroll === "function")
166 $scrollbar.onScroll(scroll);
167 }
168 }
169 }
170
171 /**
172 *

Callers

nothing calls this directly

Calls 1

onScrollMethod · 0.80

Tested by

no test coverage detected