added code example
This commit is contained in:
18
content/docs/2023/mediaart-programming2/10/autoscroll.js
Normal file
18
content/docs/2023/mediaart-programming2/10/autoscroll.js
Normal file
@@ -0,0 +1,18 @@
|
||||
async function autoScroll(page, maxScrolls) {
|
||||
await page.evaluate(async maxScrolls => {
|
||||
await new Promise((then) => {
|
||||
let distance = 1000;
|
||||
let scrolls = 0;
|
||||
let timer = setInterval(() => {
|
||||
window.scrollBy(0, distance);
|
||||
scrolls += 1;
|
||||
if (scrolls >= maxScrolls) {
|
||||
clearInterval(timer);
|
||||
then();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
}, maxScrolls);
|
||||
}
|
||||
|
||||
exports.autoScroll = autoScroll;
|
||||
Reference in New Issue
Block a user