Skip to content
Advertisement

Best way to scrolldown onpageload

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?

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement