Javascript window.scrollBy has no effect

时间:2019-04-17 00:23:12

标签: javascript

I'm using this javascript function to scroll down webpages by code:

window.scrollBy({ top: 300, behavior: "smooth" });"

This code works fine with my browser on many webpages.

Now I'm on web.whatsapp.com, and the function doesn't do anything.

I can scroll using the arrow keys on the keyboard and by using the mouse wheel, but not using this code.

What could I investigate what goes wrong here?

Thank you.

1 个答案:

答案 0 :(得分:1)

By the time of this writing, web.whatsapp.com does not have a scrollable window. However, the scrollBy function can also be used to scroll other containers.

Try this to scroll the chat list:

document.getElementById('pane-side').scrollBy({top: 100})

The current obfuscated class for the container wrapping a chat's messages is _2nmDZ:

document.querySelector('._2nmDZ').scrollBy({top: 100})

Note that both the side panel ID and the chat panel class most certainly will change in the future.