<gh_stars>10-100
{"ast":null,"code":"import raf from 'raf';\nimport getScroll from './getScroll';\nimport { easeInOutCubic } from './easings';\nexport default function scrollTo(y) {\n  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n  var _options$getContainer = options.getContainer,\n      getContainer = _options$getContainer === void 0 ? function () {\n    return window;\n  } : _options$getContainer,\n      callback = options.callback,\n      _options$duration = options.duration,\n      duration = _options$duration === void 0 ? 450 : _options$duration;\n  var container = getContainer();\n  var scrollTop = getScroll(container, true);\n  var startTime = Date.now();\n\n  var frameFunc = function frameFunc() {\n    var timestamp = Date.now();\n    var time = timestamp - startTime;\n    var nextScrollTop = easeInOutCubic(time > duration ? duration : time, scrollTop, y, duration);\n\n    if (container === window) {\n      window.scrollTo(window.pageXOffset, nextScrollTop);\n    } else {\n      container.scrollTop = nextScrollTop;\n    }\n\n    if (time < duration) {\n      raf(frameFunc);\n    } else if (typeof callback === 'function') {\n      callback();\n    }\n  };\n\n  raf(frameFunc);\n}","map":{"version":3,"sources":["_util/scrollTo.js"],"names":["options","getContainer","callback","duration","container","scrollTop","getScroll","startTime","Date","frameFunc","timestamp","time","nextScrollTop","easeInOutCubic","window","raf"],"mappings":"AAAA,OAAA,GAAA,MAAA,KAAA;AACA,OAAA,SAAA,MAAA,aAAA;AACA,SAAA,cAAA,QAAA,WAAA;AACA,eAAe,SAAA,QAAA,CAAA,CAAA,EAAmC;AAAA,MAAdA,OAAc,GAAA,SAAA,CAAA,MAAA,GAAA,CAAA,IAAA,SAAA,CAAA,CAAA,CAAA,KAAA,SAAA,GAAA,SAAA,CAAA,CAAA,CAAA,GAAJ,EAAI;AAAA,MAAA,qBAAA,GACoBA,OADpB,CAAA,YAAA;AAAA,MACtCC,YADsC,GAAA,qBAAA,KAAA,KAAA,CAAA,GACvB,YAAA;AAAA,WAAA,MAAA;AADuB,GAAA,GAAA,qBAAA;AAAA,MACTC,QADS,GACoBF,OADpB,CAAA,QAAA;AAAA,MAAA,iBAAA,GACoBA,OADpB,CAAA,QAAA;AAAA,MACCG,QADD,GAAA,iBAAA,KAAA,KAAA,CAAA,GAAA,GAAA,GAAA,iBAAA;AAE9C,MAAMC,SAAS,GAAGH,YAAlB,EAAA;AACA,MAAMI,SAAS,GAAGC,SAAS,CAAA,SAAA,EAA3B,IAA2B,CAA3B;AACA,MAAMC,SAAS,GAAGC,IAAI,CAAtB,GAAkBA,EAAlB;;AACA,MAAMC,SAAS,GAAG,SAAZA,SAAY,GAAM;AACpB,QAAMC,SAAS,GAAGF,IAAI,CAAtB,GAAkBA,EAAlB;AACA,QAAMG,IAAI,GAAGD,SAAS,GAAtB,SAAA;AACA,QAAME,aAAa,GAAGC,cAAc,CAACF,IAAI,GAAJA,QAAAA,GAAAA,QAAAA,GAAD,IAAA,EAAA,SAAA,EAAA,CAAA,EAApC,QAAoC,CAApC;;AACA,QAAIP,SAAS,KAAb,MAAA,EAA0B;AACtBU,MAAAA,MAAM,CAANA,QAAAA,CAAgBA,MAAM,CAAtBA,WAAAA,EAAAA,aAAAA;AADJ,KAAA,MAGK;AACDV,MAAAA,SAAS,CAATA,SAAAA,GAAAA,aAAAA;AACH;;AACD,QAAIO,IAAI,GAAR,QAAA,EAAqB;AACjBI,MAAAA,GAAG,CAAHA,SAAG,CAAHA;AADJ,KAAA,MAGK,IAAI,OAAA,QAAA,KAAJ,UAAA,EAAoC;AACrCb,MAAAA,QAAQ;AACX;AAfL,GAAA;;AAiBAa,EAAAA,GAAG,CAAHA,SAAG,CAAHA;AACH","sourcesContent":["import raf from 'raf';\nimport getScroll from './getScroll';\nimport { easeInOutCubic } from './easings';\nexport default function scrollTo(y, options = {}) {\n    const { getContainer = () => window, callback, duration = 450 } = options;\n    const container = getContainer();\n    const scrollTop = getScroll(container, true);\n    const startTime = Date.now();\n    const frameFunc = () => {\n        const timestamp = Date.now();\n        const time = timestamp - startTime;\n        const nextScrollTop = easeInOutCubic(time > duration ? duration : time, scrollTop, y, duration);\n        if (container === window) {\n            window.scrollTo(window.pageXOffset, nextScrollTop);\n        }\n        else {\n            container.scrollTop = nextScrollTop;\n        }\n        if (time < duration) {\n            raf(frameFunc);\n        }\n        else if (typeof callback === 'function') {\n            callback();\n        }\n    };\n    raf(frameFunc);\n}\n"]},"metadata":{},"sourceType":"module"}