Answers for "jquery click scroll to section"

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
-1

jquery scroll to position

jQuery(document).ready(function($) {
  $('a[href^="#"]').bind('click.smoothscroll',function (e) {
    e.preventDefault();
    var target = this.hash,
        $target = $(target);

    $('html, body').stop().animate( {
      'scrollTop': $target.offset().top-40
    }, 900, 'swing', function () {
      window.location.hash = target;
    } );
  } );
} );
Posted by: Guest on January-02-2021

Code answers related to "jquery click scroll to section"

Code answers related to "Javascript"

Browse Popular Code Answers by Language