jQuery animated scroll is not working

82 views Asked by At

I need to scroll the point of view to the new added textbox.

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

But it is not working. I don't see any errors in page explorer.

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

And this code is working well, but it is not animated scroll.

1

There are 1 answers

1
Mohi On BEST ANSWER

Try this code:

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

And register it like this:

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