Asp.net 无法拖动我的滚动条

Asp.net 无法拖动我的滚动条,asp.net,updatepanel,Asp.net,Updatepanel,下面是聊天脚本。每当我尝试向上拖动时,滚动条都会向下拖动。如何允许在下面的代码中拖动 有没有其他方法使我的代码更好,并允许滚动 default.aspx <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml

下面是聊天脚本。每当我尝试向上拖动时,滚动条都会向下拖动。如何允许在下面的代码中拖动

有没有其他方法使我的代码更好,并允许滚动

default.aspx

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div id="div1" style="height:400px; width:400px; overflow:auto; z-index:1">
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick" />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
            <ContentTemplate>
                <div id="div2" style="height:300px; width:350px">
                <asp:BulletedList ID="BulletedList1" runat="server" />
                </div>
                <div id="div4" style="position:absolute; left:500px; bottom:50px; z-index:10">
                <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
                </div>
                </div>
            </ContentTemplate>
            </asp:UpdatePanel>
            <div id="div5" style="position:absolute; left:100px; bottom:50px; z-index:10">
            <asp:TextBox ID="TextBox1" runat="server"/>
            </div>
    </form>
    <script type="text/javascript">
        function _SetChatTextScrollPosition() {
            var chatText = document.getElementById("div1");
            chatText.scrollTop = chatText.scrollHeight;
            window.setTimeout("_SetChatTextScrollPosition()", 1);
        }

        window.onload = function () {
            _SetChatTextScrollPosition();
        }
        </script>
</body>
</html>

您的滚动不起作用,因为每1毫秒您就会告诉它滚动到div1的底部(这就是您的
\u setchatterxtscrollposition()
函数所做的)。因为你的超时等待时间很短,一旦你放开滚动条,它就会再次向下滚动


因此,如果希望能够向上滚动,则必须停止使用此函数,或者将超时间隔设置为更长的时间(以毫秒为单位,因此1000==1秒)这样,您至少有机会滚动并查看,然后它会将您踢回底部。

我认为解决方案是检测用户当前是否正在滚动浏览器窗口。 如果是,则不设置滚动位置,否则请滚动div元素

Javascript更改

var isScrolling;
document.observe('user:scrolling', function() { isScrolling = true; });

function _SetChatTextScrollPosition() {
      if(!isScrolling) {
            var chatText = document.getElementById("div1");
            chatText.scrollTop = chatText.scrollHeight;
            window.setTimeout("_SetChatTextScrollPosition()", 1);
      }
      isScrolling = false;
}
<body onscroll="document.fire('user:scrolling')">
HTML更改

var isScrolling;
document.observe('user:scrolling', function() { isScrolling = true; });

function _SetChatTextScrollPosition() {
      if(!isScrolling) {
            var chatText = document.getElementById("div1");
            chatText.scrollTop = chatText.scrollHeight;
            window.setTimeout("_SetChatTextScrollPosition()", 1);
      }
      isScrolling = false;
}
<body onscroll="document.fire('user:scrolling')">

希望这对你有帮助

谢谢和问候


刺耳的声音。

我的问题是如何滚动。不要延迟滚动。滚动条应该完全在我的控制下,而不是使用更新面板。如果我关闭计时器,聊天信息怎么不会更新?我没说要停止服务器端计时器。我是说删除_setchattextScrollPositionJavaScript函数。它所做的就是每1毫秒将div的位置设置到底部。它与更新聊天信息无关。这也是您的滚动无法正常工作的原因。删除该选项后,我的滚动条将在计时器更新时重置为顶部:(我的回答对你很有帮助?你自己找到解决办法了吗?)??