Yesterday there is a need, is to want to load the page after the left automatically scroll a certain position.
Always thought that as long as the page document.documentElement.scrollLeft set a numerical value to be effective, the result is disappointed ~
Today, I found out:
The use of Document.documentElement.scrollLeft set values, must be triggered by human events to take effect;
To automatically scroll a certain distance when the page is loaded, use the animate of jquery, as in the following example:
$ ("Html,body"). Animate ({"ScrollLeft": "300px"}, 1000);
$ ("Html,body"). Animate ({"scrolltop": "300px"}, 1000);
Demo
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title> Automatic scrolling </title>
<meta name= "keywords" content= ""/>
<meta name= "description" content= ""/>
<script type= "Text/javascript" src= "Https://www.gamebox.com/js/jquery.js" ></script>
<body>
<!--container start-->
<div class= "Container" style= "height:3000px; width:3000px; " >
<a class= "btn" href= "javascript:;" > Click </a>
</div>
<!--container end-->
<script type= "Text/javascript" >
/*window.onload = function () {
Window.Scroll (0,300);
$ (". Btn"). On ("click", Function () {
Document.documentElement.scrollLeft = "500";
var otop = Document.body.scrollTop | | Document.documentElement.scrollTop;
var oleft = Document.body.scrollLeft | | Document.documentElement.scrollLeft;
alert (oleft);
});
}*/
$ (function () {
$ ("Html,body"). Animate ({"ScrollLeft": "300px"}, 1000);
});
</script>
</body>