I use the following in order scrolling to top. How could i edit it so the top is set by a div tag?
var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
pageRequestManager.add_endRequest(function() {
$('html, body').animate({ scrollTop: 0 }, 'slow');
});
// get the "Div" inside which you wish to scroll (i.e. the container element) const El = document. getElementById('xyz'); // Lets say you wish to scroll by 100px, El. scrollTo({top: 100, behavior: 'smooth'}); // If you wish to scroll until the end of the container El. scrollTo({top: El.
scrollTop() method: It is used to set the vertical position of the scroll bar to the value 'val'. offSet() Method: It is used to get the coordinates of the first element in the set of all matched elements. Example 1: This example describes how to scroll a specific element using jQuery.
click(function(event) { event. preventDefault(); $. scrollTo($('#myDiv'), 1000); });
If your CSS html element has the following overflow markup, scrollTop will not function. To allow scrollTop to scroll, modify your markup remove overflow markup from the html element and append to a body element.
You need to use .offset()
to get the correct position value like:
$('html, body').animate({ scrollTop: $('#div').offset().top }, 'slow');
.offset
returns the current position of an element relative to the document.
References: .position(), .offset()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With