How to implement the "Go to top" functionality?

I work with ExtJS4 and am looking for a way to implement Back to Top functionality.

i.e. When you click the top button, the view should scroll back to the top of the component. How can I achieve this in ExtJS?

+6
source share
2 answers

In addition to rixo's answer (which would be the easiest way to scroll to the absolute top), I want to mention that there is also a component-level implementation ( scrollBy ), which can be convenient if you don't need to scroll the whole window.

Update

I must admit that I never used scrollBy myself, so if this does not work for you (the associated API should provide you with all the information) I recommend that you use scrollTo () . JSFiddle works here

Use it in a panel, for example

 panel.getEl().scrollTo('Top', 0, true); // or panel.body.scrollTo('Top', 0, true); // this property is protected // or panel.getTargetEl().scrollTo('Top', 0, true); // this method is private and may be changed 

and on Treepanel or Gridpanel for example

 panel.getView().getEl().scrollTo('Top', 0, true); 
+5
source

Use window.scrollTo(0,0) in your click handler.

+2
source

Source: https://habr.com/ru/post/946307/


All Articles