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
SalesForce_52436SalesForce_52436 

How Scroll to Top of page in component?

Hi,

I Want to scroll to top of the page to indicate that error has occured. When i am try to display the error message page is not scrolling to top when error is occured.i want to auto scroll top when error occured in lightning component.Please help me its urgent.
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Please refer to the below links which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/78514/scroll-to-top-in-a-lightning-component

https://salesforce.stackexchange.com/questions/197200/scroll-page-to-top-onclick-of-a-button-in-saleforce1

https://developer.salesforce.com/forums/?id=9060G0000005YtaQAE

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
SalesForce_52436SalesForce_52436
Hi Khan,

I have already seen all of these none of them is worked for me? If you got any solution please help me to write the code iam new to lightning.

Thanks
SalesForce_52436SalesForce_52436
Hi all,

I have tried window.scroll(0,0) , this is working in lightning component but not in lightning quick action. I want to scroll to top when button is clicked in lightning quick action. PLease help me.

Thanks
Raj DharsandiaRaj Dharsandia

Hi SalesForce_52436

i too want to scroll to top in lightning quick action please share the soln if you have found any .

it would be really helpful.

Thanks,

Ayan Sarkar 37Ayan Sarkar 37
To make the scrollTop = 0 to work the container div has to have an internal scroll. Which we can get by either giving a height via px or via vh.
Try that out it should work. I was facing a similar issue while adding LWC inside Flexi Page. The Flexi page has its own scroller but for that, the scrollTop doesn't work. But if we create a separate scroller at the top-level div then the scrollTop starts to work.
Check this out. I have created this and it works perfectly fine for me: https://webcomponents.dev/edit/3vpWJ46hxykfPSACfuNN
Mahender Reddy GanguMahender Reddy Gangu
Hi Raj, 
Have you found a way to scroll to top in quick action?
Vishwas B NVishwas B N
Hi @Ayan Sarkar 37,
I had a similar requirement , when ever we switch between tabs within a lightning page the element should be disaplaying from top of the screen instead of the position we scrolled in the previous operation.
Your solution has worked perfect for me. Thank you..
Nancy Everest --Nancy Everest --
Per the first link above (https://salesforce.stackexchange.com/questions/78514/scroll-to-top-in-a-lightning-component) from Kahn Anas, this worked for me:
declaration at top:
scrollOptions = {
        left: 0,
        top: 0,
        behavior: 'smooth'
    }
and then in my function:
window.scrollTo(this.scrollOptions)
Bhagyashri DeoreBhagyashri Deore
This solution helped me. Thank you @Nancy Everest