js scrollTop, 滚动条操作

设置页面加载时滚动条自动滚到底的方法:

jQuery:


复制代码 代码如下:


 $(function(){
   var h = $(document).height()-$(window).height();
   $(document).scrollTop(h);
 });



JavaScript:


复制代码 代码如下:


 window.onload = function(){
   var h = document.documentElement.scrollHeight || document.body.scrollHeight;
   window.scrollTo(h,h);
 }

<button onclick="text1.scrollTop=text1.scrollHeight">滚动</button><br>

cache the xmlhttprequest instance, if you want to use setinterval or settimeout. or, there might be a memory leap.

  

原文地址:https://www.cnblogs.com/hualiu0/p/5274037.html