简体   繁体   中英

How to scroll down a web page using javascript?

Hy community, I have used the following code for scrolling pages

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

It worked fine for almost all of the web pages but I recently encountered a web page where this snippet doesn't work. Go to this link https://www.holonis.com/christineboctor , Click on Followers and then try to scroll down with this code and it won't work. Is there anyone who knows how to deal with it? I am novice in JavaScript, any help would be greatly appreciated. Thanks

You can try like this

       var scrolltop = $('.w-modal-follow-list.w-modal-followers').offset().top ;
       window.scrollTo(0, scrolltop );

.offset().top will find position of div from top and you can set it like window.scrollTo(0, scrolltop )

Try $('.w-modal-follow-list.w-modal-followers').scrollTop(500) . Where 500 is your scroll value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM