Scroll to a div using jquery

There is no .scrollTo() method in jQuery, but there is a .scrollTop() one. .scrollTop expects a parameter, that is, the pixel value where the scrollbar should scroll to.



will scroll the window (if there is enough content in it).

So you can get this desired value with .offset() or .position()


So this is how you could animate the jump using jquery. No-js fallback is a normal jump without animation.

Original example:


$(document).ready(function() {
  $(".jumper").on("click", function( e ) {


    $("body, html").animate({ 
      scrollTop: $( $(this).attr('href') ).offset().top 
    }, 600);

#long {
  height: 500px;
  background-color: blue;
<script src=""></script>
<!-- Links that trigger the jumping -->
<a class="jumper" href="#pliip">Pliip</a>
<a class="jumper" href="#ploop">Ploop</a>
<div id="long">...</div>
<!-- Landing elements -->
<div id="pliip">pliip</div>
<div id="ploop">ploop</div>

Live Example

Leave a Reply

Your email address will not be published. Required fields are marked *