首页 > 解决方案 > ScrollTo within a div on a page

问题描述

I am trying to scroll down a page to load more content. Normally I would do the following:

window.scrollTo(0, document.body.scrollHeight);

However, I have a page where it is only a left sidebar that needs to be scrolled, and doing something like the following does not work. See image here --

enter image description here

How would I scroll down the left sidebar? The xpath of the containing element is: //li[contains(@class, "search-result")]

标签: javascripthtml

解决方案


用这个:

var objDiv = document.getElementById("your_div"); objDiv.scrollTop = objDiv.scrollHeight;


推荐阅读