【问题标题】:jQuery animated scroll is not workingjQuery动画滚动不起作用
【发布时间】:2014-11-23 15:27:33
【问题描述】:

我需要将视图滚动到新添加的文本框。

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ScrollTo" + ClientId, "jQuery(function(){$('html, body').delay(2000).animate({ scrollTop: $(document.getElementById(\"" + ClientId + "\")).offset().top },2000);});", true);    

但它不起作用。 我在页面资源管理器中没有看到任何错误。

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ScrollTo" + ClientId, "document.getElementById(\"" + ClientId + "\").scrollIntoView(true);", true);    

而且这段代码运行良好,但不是动画滚动。

【问题讨论】:

  • 把浏览器给你的错误放上去

标签: javascript scriptmanager


【解决方案1】:

试试这个代码:

string javascript=@"
jQuery(document).ready(function(){
    jQuery('html, body')
        .delay(2000)
        .animate(
            {
                'scrollTop': jQuery('#"+ ClientId +@"').offset().top + 'px'
            },
            2000);
});
"

并像这样注册它:

ScriptManager.RegisterStartupScript
(
    Page,
    Page.GetType(),
    "ScrollTo" + ClientId,
    javascript,true
);  

【讨论】:

  • 我的 JS/jQuery 知识水平是“非常入门”。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-07
  • 1970-01-01
  • 2018-01-02
  • 1970-01-01
  • 2016-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多