@sberdevices/plasma-temple
Version:
SberDevices CanvasApp Templates.
44 lines (37 loc) • 1.28 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.scroll = scroll;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function scroll(_ref) {
var element = _ref.element,
offset = _ref.offset,
_ref$startPosition = _ref.startPosition,
startPosition = _ref$startPosition === void 0 ? 0 : _ref$startPosition,
_ref$duration = _ref.duration,
duration = _ref$duration === void 0 ? 400 : _ref$duration,
_ref$axis = _ref.axis,
axis = _ref$axis === void 0 ? 'x' : _ref$axis;
var start = 0;
var scrollStart = startPosition;
var direction = {
x: 'left',
y: 'top'
}[axis];
requestAnimationFrame(function animate(timestamp) {
if (start === 0) {
start = timestamp;
}
var timeFraction = (timestamp - start) / duration;
if (timeFraction > 1) {
timeFraction = 1;
}
var diff = Math.ceil(offset * timeFraction);
element.scrollTo(_defineProperty({}, direction, scrollStart + diff));
if (timeFraction < 1) {
requestAnimationFrame(animate);
}
});
}
//# sourceMappingURL=scroll.js.map
;