I\'m trying to figure out how get the page automaticlly scroll to a specific div when the page has loaded. I have tried using the jQuery scroll function, but cant get it to
$(document).ready(function(){
$("html, body").animate({
scrollTop: $('.sb-menu').offset().top
}, 1000);
});
You can do this using the .animate() method:
$(document).ready(function () {
// Handler for .ready() called.
$('html, body').animate({
scrollTop: $('#what').offset().top
}, 'slow');
});
what
FIDDLE
Firsts you have to call the file,
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
Here the id is 'scroll'. The following code is helpful:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// Handler for .ready() called.
$('html, body').animate({
scrollTop: $('#scroll').offset().top
}, 'slow');
});
</script>
</head>
<body>
<div id="scroll"></div>
</body>
</html>