使用动画vb.net滚动到页面底部

时间:2017-05-12 06:44:17

标签: jquery css vb.net animation scroll

我正在尝试创建一个可从移动设备和PCS访问的登录页面。在我的表格底部(大约位于页面底部),我显示标签错误。问题是,在小型设备上变得可见时,除非向下滚动屏幕,否则用户无法看到它。所以我尝试使用下面的jquery进行自动滚动:

 $("html, body").animate({ scrollTop: $("#LabelError").offset().top }, 500);

这是完美的,但我需要使用vb.NET从服务器端进行,但我不知道如何。有帮助吗?

2 个答案:

答案 0 :(得分:0)

您可以在VB.Net中注册和使用JS,如:

在html中定义错误div(Default.aspx或其他):

<div id="ErrorDiv">Error</div> 

然后从vb.net调用它就像

ClientScript.RegisterStartupScript([GetType](), "SetFocus", "window.location.hash = '#ErrorDiv';", True)

点击事件示例:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Response.Redirect(String.Format("{0}#{1}", Request.RawUrl, "ErrorDiv"))
        ClientScript.RegisterStartupScript([GetType](), "SetFocus", "window.location.hash = '#ErrorDiv';", True)
    End Sub

答案 1 :(得分:0)

好的,我解决了。 当使用jquery:

显示标签时,我处理了事件
$(function () {

   var observer = new MutationObserver(function (mutations) {
     $("html, body").animate({ scrollTop: $("#LabelError").offset().top }, 500);
     $("#LabelError").focus();
  });

  var target = document.querySelector('#LabelError');
  observer.observe(target, {
      attributes: true
  });

});