开发者

How to use window.scroll to automatically scroll on pageload?

function Scrolldown() {
        window.scroll(0,300); 
    }

开发者_JS百科How can I use this function (or a similar one) to automatically scroll down when the page loads? (without clicking a link)

Regards,

taylor


Give this a try:

function Scrolldown() {
     window.scroll(0,300); 
}

window.onload = Scrolldown;


you could include all of your javascript in an event. This will scroll to an element with an id.

<body onload="window.location='#myID';">


You could use window.onload:

window.onload = Scrolldown;

I also want to point out that you could use an HTML anchor to indicate where to scroll to, so you don't have to hard-code the pixel value:

<div id="iWantToScrollHere" name="iWantToScrollHere">
    ...
</div>

...which would make your Scrolldown function:

function Scrolldown() {
    window.location.hash = '#iWantToScrollHere';
}


you could include jquery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

and then wrap your scrolling thing in a document ready function:

$(document).ready(function(){

window.scroll(0,300);

});

then after that you don't need to do anything.

:)


well, another super simple script is here,

<script type="text/javascript">
window.onload = function(e){ 
    window.scrollBy(1,1);
}

it worked best for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜