2014-11-23 125 views
0

我需要将视角滚动到新添加的文本框。jQuery动画滚动不起作用

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);  

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

+0

把错误的浏览器提供的JS/jQuery的的 – rejnev 2014-11-23 17:17:49

回答

0

试试这个代码:

string [email protected]" 
jQuery(document).ready(function(){ 
    jQuery('html, body') 
     .delay(2000) 
     .animate(
      { 
       'scrollTop': jQuery('#"+ ClientId [email protected]"').offset().top + 'px' 
      }, 
      2000); 
}); 
" 

而且这样注册它:

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

我的知识水平是 “非常入门”。非常感谢你! – 2014-11-25 08:55:12