Tuesday, 13 August 2013

continue the `while` loop when setInterval is finished

continue the `while` loop when setInterval is finished

I have a code that scrolls a growing page to the bottom (till it's not
possible to scroll to the bottom). when it's not possible, it scrolls to
the top and the javascript code is finished.
for example, imagine a timeline on facebook. It's a growing page, so I can
scroll it again and again till it's not possible to scroll (then I will be
in: "BORN").
so this is my code:
while (i < elements.Count)
{
js.ExecuteScript("var timeId = setInterval( function() {
if(window.scrollY<(document.body.scrollHeight-window.screen.availHeight))
window.scrollTo(0,document.body.scrollHeight); else {
clearInterval(timeId);
window.scrollTo(0,0); } },5000);");
i++;
}
I want to add 1 to i only when the setInterval is finished.
how can I do it please?

No comments:

Post a Comment