Scroll Automatically to the Bottom of the Page

后端 未结 24 2890
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 05:22

Consider I have a list of questions. When I click on the first question, it should automatically take me to the bottom of the page.

For a matter of fact, I do know

24条回答
  •  Happy的楠姐
    2020-11-22 05:59

    Here's my solution:

     //**** scroll to bottom if at bottom
    
     function scrollbottom() {
        if (typeof(scr1)!='undefined') clearTimeout(scr1)   
        var scrollTop = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
        var scrollHeight = (document.documentElement && document.documentElement.scrollHeight) || document.body.scrollHeight;
        if((scrollTop + window.innerHeight) >= scrollHeight-50) window.scrollTo(0,scrollHeight+50)
        scr1=setTimeout(function(){scrollbottom()},200) 
     }
     scr1=setTimeout(function(){scrollbottom()},200)
    

提交回复
热议问题