Answer the question
In order to leave comments, you need to log in
How to return a value from a function strictly after scrolling the entire page?
I use not a phantom as in tags, but a slimer (not in tags), because you can see what is happening.
I want the value to return after all ScrollTo, but it returns much earlier. How to do it right?
ScrollTo - jquery plugin
page.evaluate(function() {
function unique(arr) {
var obj = {};
for(var i=0; i<arr.length; i++) {
var str = arr[i];
obj[str] = true;
}
return Object.keys(obj);
}
function getLinks(){
var links = new Array();
var collect = $('div.coefficient__more > a');
collect.each(function(index, element){
links.push($(element).attr('href'))
});
return links;
}
var hrefs = new Array();
var num;
var dl = 500;
$(window).queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).scrollTo("10%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("20%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("30%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("40%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("50%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("60%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("70%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("80%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("90%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
}).delay(dl).scrollTo("100%").queue(function() {
hrefs = hrefs.concat(getLinks());
$(this).dequeue();
});
return unique(hrefs);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question