UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

60 lines (55 loc) 1.99 kB
'use strict'; var tslib_es6 = require('./tslib.es6-01322ba9.js'); function autoScroll(element, page, bottomTimes) { if (bottomTimes === void 0) { bottomTimes = 0; } return tslib_es6.__awaiter(this, void 0, void 0, function () { return tslib_es6.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, page.evaluate(function (_a) { var element = _a.element, bottomTimes = _a.bottomTimes; return new Promise(function (resolve) { var UNIT_DISTANCE = 100; var ele = document.querySelector(element); var totalHeight = 0; var curBottomTimes = 0; var lastScrollHeight = ele === null || ele === void 0 ? void 0 : ele.scrollHeight; var doScroll = function doScroll(ele) { totalHeight = ele.scrollTop + UNIT_DISTANCE; ele.scrollTop = totalHeight; }; var timer = setInterval(function () { var scrollHeight = ele.scrollHeight; doScroll(ele); if (scrollHeight > lastScrollHeight) { curBottomTimes += 1; lastScrollHeight = scrollHeight; } console.log('[autoScroll] scrollHeight & totalHeight', scrollHeight, totalHeight); if (totalHeight >= scrollHeight || bottomTimes && curBottomTimes > bottomTimes) { console.log('[autoScroll] end'); clearInterval(timer); resolve(1); } }, 100); }); }, { element: element, bottomTimes: bottomTimes })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); } var scroll = /*#__PURE__*/Object.freeze({ __proto__: null, autoScroll: autoScroll }); exports.autoScroll = autoScroll; exports.scroll = scroll;