2

I am using a javascript code for the F12 console to automatically scroll down. It works fine, but I want it to stop after 250 times. How to do that?

var scroll = setInterval(function(){ window.scrollBy(0,1000); }, 2000);
hgb123
  • 13,869
  • 3
  • 20
  • 38

3 Answers3

1

var count = 1;
var scroll = setInterval(() =>  this.executeInterval(), 10);

function executeInterval() {
   window.scrollBy(0,1000); 
   console.log(count)
   if(count == 250) clearInterval(scroll);

   count++;
}

Forgot the function. press on run code snippet.

nosTa
  • 607
  • 6
  • 16
1

You can use clearInterval() to cancel a repeating action which was established with setInterval().

Read the docs here :)

pitamer
  • 905
  • 3
  • 15
  • 27
1
var scroll = setInterval(function(){ window.scrollBy(0,1000); }, 2000);

setTimeout(function() {
   clearInterval(scroll)
}, 250 * 2000)
Terence Cheng
  • 594
  • 2
  • 4