I have a gridview inside a div.. I want to scroll to top of the div from the bottom of the div using jquery.. Any suggestion..
//
Use the following function
window.scrollTo(xpos, ypos)
Here xpos is Required. The coordinate to scroll to, along the x-axis (horizontal), in pixels
ypos is also Required. The coordinate to scroll to, along the y-axis (vertical), in pixels
This is my solution to scroll to the top on a button click.
$(".btn").click(function () {
if ($(this).text() == "Show options") {
$(".tabs").animate(
{
scrollTop: $(window).scrollTop(0)
},
"slow"
);
}
});
Special thanks to Stoic for
$("#miscCategory").animate({scrollTop: $("#miscCategory").offset().top});
You could just use:
<div id="GridDiv">
// gridview inside...
</div>
<a href="#GridDiv">Scroll to top</a>
Here is what you can do using jquery:
$('#A_ID').click(function (e) { //#A_ID is an example. Use the id of your Anchor
$('html, body').animate({
scrollTop: $('#DIV_ID').offset().top - 20 //#DIV_ID is an example. Use the id of your destination on the page
}, 'slow');
});
I don't know why but you have to add a setTimeout with at least for me 200ms:
setTimeout( function() {$("#DIV_ID").scrollTop(0)}, 200 );
Tested with Firefox / Chrome / Edge.