Hi @HOUSSEM MAHJOUBI ,
Your code is setting the window's scrollbar, so it doesn't work.
What you need to set is the scrollbar of the panel.$("#pnlScroll").scroll
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnScrollToTop").hide();
$(function () {
$("#pnlScroll").scroll(function () {
if ($(this).scrollTop() > 10) {
$('#btnScrollToTop').fadeIn();
} else {
$('#btnScrollToTop').fadeOut();
}
});
$('#btnScrollToTop').click(function () {
$('#pnlScroll').animate({
scrollTop: 0
}, 800);
return false;
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel ID="pnlScroll" ScrollBars="Vertical" runat="server" Height="400px"
Width="300px">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"></asp:GridView>
<asp:Button ID="btnScrollToTop" CssClass="button" Text="Scroll up" runat="server" />
</asp:Panel>
</form>
</body>
</html>
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.