+ Start a Discussion
Jansi AJansi A 

Scroll to top of Lightning Component by default in SF1


We are building a Lightning App with Lightning Components for SF1. The main Component have all the child Components included, in which we are hiding and showing the Components based on our requirement. Suppose if we have shown a Component1 and scroll to end of this Component, where click on a button which will hide the Component1 and shown the Component2. The Component2 is shown, but user needs to scroll up to see the Component2 content. So how to scroll to top of the page by default on load of Component2?

We have searched for this solution and found 'force:navigateToURL' will work. I have tried this, which is working but through this unable to pass the Parameter of Array of Objects type(Ex: Account[]). Also found that this is not recommended by SFDC as it is not documented this yet. Is this true?

Also tried the below approach, specified in the below URL, navigation is working but scroll to top of the Component is not working .

Also tried with JQuery - jQuery('html,body').animate({scrollTop:0},0);  which is not working inside SF1.

Tried the below code also, which is not working in SF1.

var cssScrolltoTop = $(".scroller"); // css class to find scroll position
    if (cssScrolltoTop) {
        var cssScrolltoTopTransform = cssScrolltoTop.css("transform");
        if (cssScrolltoTopTransform) {
            cssScrolltoTop.css("transform", "translate3d(0px, 0px, 0px)"); //set 'transform' since lighntning architecture uses css 'transfrom' property to scroll

Please let me know if you found any work around for the above issue.


NagendraNagendra (Salesforce Developers) 
Hi Jansi,

Please check with below post from stack exchange community with similar issue and proper solution which helps you to accelerate further with the above requirement. Mark this post as solved if the information helps.

Best Regards,