* Pushes scroll actions to the scrolling queue.
(elem, left, top)
| 307 | * Pushes scroll actions to the scrolling queue. |
| 308 | */ |
| 309 | function scrollArray(elem, left, top) { |
| 310 | directionCheck(left, top); |
| 311 | if (options.accelerationMax != 1) { |
| 312 | let now = dateNow(); |
| 313 | let elapsed = now - lastScroll; |
| 314 | if (elapsed < options.accelerationDelta) { |
| 315 | let factor = (1 + 50 / elapsed) / 2; |
| 316 | if (factor > 1) { |
| 317 | factor = Math.min(factor, options.accelerationMax); |
| 318 | left *= factor; |
| 319 | top *= factor; |
| 320 | } |
| 321 | } |
| 322 | lastScroll = dateNow(); |
| 323 | } |
| 324 | // push a scroll command |
| 325 | que.push({ |
| 326 | x: left, |
| 327 | y: top, |
| 328 | lastX: left < 0 ? 0.99 : -0.99, |
| 329 | lastY: top < 0 ? 0.99 : -0.99, |
| 330 | start: dateNow(), |
| 331 | }); |
| 332 | // don't act if there's a pending frame loop |
| 333 | if (pending) { |
| 334 | return; |
| 335 | } |
| 336 | let scrollRoot = getScrollRoot(); |
| 337 | let isWindowScroll = elem === scrollRoot || elem === document.body; |
| 338 | // if we haven't already fixed the behavior, |
| 339 | // and it needs fixing for this sesh |
| 340 | if (elem.$scrollBehavior == null && isScrollBehaviorSmooth(elem)) { |
| 341 | elem.$scrollBehavior = elem.style.scrollBehavior; |
| 342 | elem.style.scrollBehavior = "auto"; |
| 343 | } |
| 344 | let step = function (time) { |
| 345 | let now = dateNow(); |
| 346 | let scrollX = 0; |
| 347 | let scrollY = 0; |
| 348 | for (let i = 0; i < que.length; i++) { |
| 349 | let item = que[i]; |
| 350 | let elapsed = now - item.start; |
| 351 | let finished = elapsed >= options.animationTime; |
| 352 | // scroll position: [0, 1] |
| 353 | let position = finished ? 1 : elapsed / options.animationTime; |
| 354 | // easing [optional] |
| 355 | if (options.pulseAlgorithm) { |
| 356 | position = pulse(position); |
| 357 | } |
| 358 | // only need the difference |
| 359 | let x = (item.x * position - item.lastX) >> 0; |
| 360 | let y = (item.y * position - item.lastY) >> 0; |
| 361 | // add this to the total scrolling |
| 362 | scrollX += x; |
| 363 | scrollY += y; |
| 364 | // update last values |
| 365 | item.lastX += x; |
| 366 | item.lastY += y; |
no test coverage detected