Surya
Surya

Reputation: 21

How do I STOP a webpage being auto scrolled again and again after it reaches to the bottom?

I am a newbie and trying to implement a JS code via Greasemonky that auto scrolls till the very bottom of the page. But if I scroll up, it keeps scrolling again so I want it to stop scrolling once I click a stop button.

// Scrolls till the bottom
setInterval(function(s){scrollBy(0,s||10000)},1000);


//script that creates a button
var input = document.createElement('input');
input.type = 'button';
input.value = 'Stop scrolling';
input.onclick = stopScroll; 
document.body.appendChild(input);

//I need help here, not sure how to use clearInterval.
function stopScroll()
{
  clearInterval();      
}

Upvotes: 0

Views: 77

Answers (1)

Branko Sego
Branko Sego

Reputation: 790

First, declare variable interval

var interval = setInterval(function(s){scrollBy(0,s||10000)},1000);

and then clean it in function

function stopScroll()
{
clearInterval(interval);      
}

Upvotes: 3

Related Questions