This is a migrated thread and some comments may be shown as answers.

Scroll to anchor after ajax

3 Answers 88 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Mattias Moberg
Top achievements
Rank 1
Mattias Moberg asked on 31 Jan 2012, 01:05 AM
Hi.
Im using the radajaxmanager.
Is there any way to scroll to anchor #posts after ajax ?

edit:
Code below is what im using to scroll to #posts
Is there any way to animate this scroll, to make it smoother ?

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(OnEndRequest);
function OnEndRequest(sender, args) {
    window.location.hash = '#posts';
}

3 Answers, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 02 Feb 2012, 06:17 PM
Hi Mattias,

You could achieve your scenario by following the code below. Note that jQuery should be included.
$telerik.$("body").animate({ scrollTop: $telerik.$("a[name='posts']").position().top }, 2000);
<telerik:RadScriptManager runat="server" ID="RadScriptManager1">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
    </Scripts>
</telerik:RadScriptManager>

Greetings,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Mattias Moberg
Top achievements
Rank 1
answered on 03 Feb 2012, 08:16 PM
Hi.
Thanks for answer. But i cannot get this to work at all.
In IE8, IE9 i get scripterror:
 Unable to get value of the property 'top': object is null or undefined

In firefox, chrome, safari nothing happends at all..
0
Mattias Moberg
Top achievements
Rank 1
answered on 05 Feb 2012, 06:00 PM
This is how I ended up and its working fine in Firefox, Safari, Chrome.
In IE9, there is a small problem. After scrolling, content on page is not selectable.

If there is a better solution, please let me know.. Thanks.

<script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(OnEndRequest);
    function OnEndRequest(sender, args) {
        $telerik.$('html, body').animate({ scrollTop: $telerik.$('#posts').offset().top }, 2000);
    }
</script>
Tags
Ajax
Asked by
Mattias Moberg
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Mattias Moberg
Top achievements
Rank 1
Share this question
or