1

I have the following code:

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

The previous code attempts to scroll down after page loading.

Is there any problem, as it doesn't work for me?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Moatasem bakri
  • 147
  • 1
  • 4
  • 16

3 Answers3

2

instead of window.onload use

    $(document).ready(function() {
        window.scrollTo(0, 100);
    }

because window.onload is fired when entire page load and document.ready is fired when DOM loads and use srcollTo instead of scroll

Khan Engineer
  • 408
  • 5
  • 23
0

Try this

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

window.onload = Scrolldown;
Reena
  • 1,109
  • 8
  • 16
0

try body onload instead:

In your html:

<body onLoad="Scrolldown()">

js:

function Scrolldown(){
window.scroll(0,100); 
}
Nishanth Matha
  • 5,993
  • 2
  • 19
  • 28
  • the problem is not in the event raising because I can achieve another work on page load, my problem just in scrolling down – Moatasem bakri Apr 07 '15 at 05:22
  • well the above solution should work pretty good. Give it a try – Nishanth Matha Apr 07 '15 at 05:23
  • between do check if you have enough content to scroll down, ie, (height of document) should be greater than (height of window) – Nishanth Matha Apr 07 '15 at 05:27
  • yeah I already make sure about that, I maybe a JavaScript library conflicts but I don't any issue in my website, I'll test it on a clean website, but can it be a browser issue !? – Moatasem bakri Apr 07 '15 at 05:32
  • browser compatibility I don't think so unless you are using old IE. JavaScript library: that's just plain JS so there should be any conflict with that. May be posting your whole code might help here. – Nishanth Matha Apr 07 '15 at 05:34