Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 以编程方式滚动到页面底部_Jquery_Ruby_Scroll - Fatal编程技术网

Jquery 以编程方式滚动到页面底部

Jquery 以编程方式滚动到页面底部,jquery,ruby,scroll,Jquery,Ruby,Scroll,我想使用Ruby脚本以编程方式滚动到页面底部,因为该网页实现了无限滚动。我可以用mechanize做这个吗 尝试使用window.scrollBy()&window.scrollTo(),这可能会有所帮助以下代码将滚动到底部,即使文档高度是动态的 const getDocHeight = function() { return Math.max( document.body.scrollHeight, document.documentElement.scrollHeight

我想使用Ruby脚本以编程方式滚动到页面底部,因为该网页实现了无限滚动。我可以用mechanize做这个吗

尝试使用window.scrollBy()&window.scrollTo(),这可能会有所帮助

以下代码将滚动到底部,即使文档高度是动态的

const getDocHeight = function() {
  return Math.max(
    document.body.scrollHeight,
    document.documentElement.scrollHeight,
    document.body.offsetHeight,
    document.documentElement.offsetHeight,
    document.body.clientHeight,
    document.documentElement.clientHeight
  );
}; 

scrollToBottom = () => {
  let maxHeight = getDocHeight();

  window.scrollBy(0, maxHeight);

  window.onscroll = function(ev) {
    if (getDocHeight() > maxHeight) {
      maxHeight = getDocHeight();

      window.scrollBy(0, maxHeight);
    }
  };
};

scrollToBottom();

我不知道。。。。你能?您尝试了什么?我想这个Answer可以帮助您:通常使用滚动触发的AJAX调用来实现无限滚动。如果你发布了你想要抓取的网站的url,我可能会告诉你更多。