2

Just to provide context: I want to simulate mouse scroll on Google photos (photos.google.com).

The page contains scroll bar only for a portion of the page (the top "Search" section does not have a scroll bar).

The following does not work (but it works fine for scrolling on say Facebook, or SO):

window.scrollTo(0, 10000000)

Any clues on how I can simulate mouse scroll ?

1 Answer 1

2

If you aren't scrolling the whole window then window.scrollTo is not what you want. You can scroll a section of DOM that has a style of overflow: scroll with something like:

var scrollBox = document.getElementById('sectionId');
scrollBox.scrollTop = 100; // num pixels from element top you want to scroll down

Which is the same as:

$('#sectionId').scrollTop(100);

You might want to consider a library like https://github.com/kswedberg/jquery-smooth-scroll which scrolls the screen in an ease-in ease-out fashion, which is easier for users to follow.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.