function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jansi AJansi A 

Scroll to top of Lightning Component by default in SF1

Hi,

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 .
https://force-base.com/2016/01/04/how-to-navigate-from-one-component-to-another-in-lightning/

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.



Regards
Jansi



 
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,
Nagendra.P