Skip to main content
Active reading [<https://en.wikipedia.org/wiki/JavaScript>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 109
  • 132

You can use jQuerysjQuery's .animate(), .offset() and scrollTop. Like

$(document.body).animate({
    'scrollTop':   $('#anchorName2').offset().top
}, 2000);

exampleExample link: http://jsbin.com/unasi3/edit

If you don't want to animate, use .scrollTop() like:

$(document.body).scrollTop($('#anchorName2').offset().top);

or javascriptsOr JavaScript's native location.hash like:

location.hash = '#' + anchorid;

You can use jQuerys .animate(), .offset() and scrollTop. Like

$(document.body).animate({
    'scrollTop':   $('#anchorName2').offset().top
}, 2000);

example link: http://jsbin.com/unasi3/edit

If you don't want to animate use .scrollTop() like

$(document.body).scrollTop($('#anchorName2').offset().top);

or javascripts native location.hash like

location.hash = '#' + anchorid;

You can use jQuery's .animate(), .offset() and scrollTop. Like

$(document.body).animate({
    'scrollTop':   $('#anchorName2').offset().top
}, 2000);

Example link: http://jsbin.com/unasi3/edit

If you don't want to animate, use .scrollTop() like:

$(document.body).scrollTop($('#anchorName2').offset().top);

Or JavaScript's native location.hash like:

location.hash = '#' + anchorid;
added 7 characters in body; added 44 characters in body; added 194 characters in body; added 60 characters in body
Source Link
jAndy
  • 234.8k
  • 57
  • 311
  • 362

You can use jQuerys .animate(), .offset() and scrollTop. Like

$(windowdocument.body).animate({
    'scrollTop':   $('#anchorName2').offset().top
}, 2000);

example link: http://jsbin.com/unasi3/edit

If you don't want to animate use .scrollTop() like

$(document.body).scrollTop($('#anchorName2').offset().top);

or javascripts native location.hash like

location.hash = '#' + anchorid;

You can use jQuerys .animate(), .offset() and scrollTop. Like

$(window).animate({
    'scrollTop':   $('#anchorName2').offset().top
}, 2000);

You can use jQuerys .animate(), .offset() and scrollTop. Like

$(document.body).animate({
    'scrollTop':   $('#anchorName2').offset().top
}, 2000);

example link: http://jsbin.com/unasi3/edit

If you don't want to animate use .scrollTop() like

$(document.body).scrollTop($('#anchorName2').offset().top);

or javascripts native location.hash like

location.hash = '#' + anchorid;
Source Link
jAndy
  • 234.8k
  • 57
  • 311
  • 362

You can use jQuerys .animate(), .offset() and scrollTop. Like

$(window).animate({
    'scrollTop':   $('#anchorName2').offset().top
}, 2000);