Answers for "jquery scroll to specific element"

1

jquery scroll to specific div

/* HTML LAYOUT */
<div class="my-div" id="login-section"></div>
/* JQUERY Code*/
$(".my-menu-link").click(function () {
  $("html, body").animate({
    scrollTop: $("#" + $(this).attr("id")).offset().top
  }, 500) /* 500 milliseconds*/
  /*
    Hint:
    $("#" + $(this).attr("id")) => #login-section
    so that html will scroll to #login-section which is our specific div
  */
})
Posted by: Guest on June-17-2021
6

jquery scroll to element

$("#button").click(function() {
    $([document.documentElement, document.body]).animate({
        scrollTop: $("#elementtoScrollToID").offset().top
    }, 2000);
});
Posted by: Guest on July-29-2020

Code answers related to "jquery scroll to specific element"

Code answers related to "Javascript"

Browse Popular Code Answers by Language