'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?
Solution 1:[1]
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
Solution 2:[2]
Try this
function Scrolldown() {
window.scroll(0,100);
}
window.onload = Scrolldown;
Solution 3:[3]
try body onload
instead:
In your html:
<body onLoad="Scrolldown()">
js:
function Scrolldown(){
window.scroll(0,100);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Reena |
Solution 3 | Nishanth Matha |