Home > Web Front-end > JS Tutorial > After the page is loaded, the scroll bar automatically scrolls to a certain position_javascript skills

After the page is loaded, the scroll bar automatically scrolls to a certain position_javascript skills

WBOY
Release: 2016-05-16 16:59:07
Original
1757 people have browsed it

Yesterday, I had a request. I wanted the page to automatically scroll to a certain position to the left after it is loaded.

I always thought that just setting a value to document.documentElement.scrollLeft on the page would take effect, but I was disappointed~
I took the time to check today and found out:
Use document.documentElement.scrollLeft to set the value. It must take effect when triggered by a human event;
If you want the page to automatically scroll a certain distance after loading, use jquery's animate, as in the following example:

$("html,body").animate( {"scrollLeft": "300px"}, 1000);
$("html,body").animate({"scrollTop": "300px"}, 1000);

demo:

Copy code The code is as follows:





Auto scroll













Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template