Answers for "how to scroll down to a particular element in jquery"

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 on scroll down

Check current scrollTop vs previous scrollTop

var lastScrollTop = 0;
$(window).scroll(function(event){
   var st = $(this).scrollTop();
   if (st > lastScrollTop){
       // downscroll code
   } else {
      // upscroll code
   }
   lastScrollTop = st;
});
Posted by: Guest on December-05-2020

Code answers related to "how to scroll down to a particular element in jquery"

Code answers related to "Javascript"

Browse Popular Code Answers by Language