I have the following code:
JavaScript
x
6
1
<script type="text/javascript">
2
window.onload = function () {
3
window.scrollBy(0, 100);
4
}
5
</script>
6
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
JavaScript
1
4
1
$(document).ready(function() {
2
window.scrollTo(0, 100);
3
}
4
because window.onload is fired when entire page load and document.ready is fired when DOM loads and use srcollTo instead of scroll