jquery scroll to specific div 1

jquery scroll to specific 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 */ })

Here is what the above code is Doing:
1. When the user clicks on the link, the click event is triggered.
2. The click event calls the animate() method.
3. The animate() method takes two parameters:
a. The first parameter is an object that specifies the CSS properties to animate.
b. The second parameter is the duration of the animation.
4. The scrollTop() method sets or returns the vertical scrollbar position for the selected elements.
5. The offset() method returns the position (relative to the document) of the first matched element.
6. The attr() method sets or returns attributes and values of the selected elements.

Similar Posts