You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 line
1.4 KiB

  1. {"ast":null,"code":"import clamp from 'lodash-es/clamp';\nvar animationIDStorage = new WeakMap();\nexport function scrollTo(scrollbar, x, y, duration, _a) {\n if (duration === void 0) {\n duration = 0;\n }\n\n var _b = _a === void 0 ? {} : _a,\n _c = _b.easing,\n easing = _c === void 0 ? defaultEasing : _c,\n callback = _b.callback;\n\n var options = scrollbar.options,\n offset = scrollbar.offset,\n limit = scrollbar.limit;\n\n if (options.renderByPixels) {\n // ensure resolved with integer\n x = Math.round(x);\n y = Math.round(y);\n }\n\n var startX = offset.x;\n var startY = offset.y;\n var disX = clamp(x, 0, limit.x) - startX;\n var disY = clamp(y, 0, limit.y) - startY;\n var start = Date.now();\n\n function scroll() {\n var elapse = Date.now() - start;\n var progress = duration ? easing(Math.min(elapse / duration, 1)) : 1;\n scrollbar.setPosition(startX + disX * progress, startY + disY * progress);\n\n if (elapse >= duration) {\n if (typeof callback === 'function') {\n callback.call(scrollbar);\n }\n } else {\n var animationID = requestAnimationFrame(scroll);\n animationIDStorage.set(scrollbar, animationID);\n }\n }\n\n cancelAnimationFrame(animationIDStorage.get(scrollbar));\n scroll();\n}\n/**\n * easeOutCubic\n */\n\nfunction defaultEasing(t) {\n return Math.pow(t - 1, 3) + 1;\n}","map":null,"metadata":{},"sourceType":"module"}