Jump back to the top of a scrollcontainer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pferft

Hi everyone,

I have a button at the bottom of a ScrollContainer. I’d like that ScrollContainer’s content-list to “jump back to the top position” when hitting that button. Any ideas how that could be done?

Thanks, for posting this question you saved my time searching for this problem.

hasnatkhan420 | 2022-12-21 17:36

:bust_in_silhouette: Reply From: jgodfrey

Just did some quick experimentation and this seems to work.

func _on_Button_pressed():
	var sb = $ScrollContainer.get_v_scrollbar()
	sb.ratio = 0

So, wire your Button’s press event to something like the above. That just gets the underlying scrollbar component and sets its ratio property to 0 (where 0 = the top and 1 = the bottom).

Works like a charm, thank you very much!

pferft | 2022-11-22 20:35

I had the same question and this works perfectly. Thank you!

n.b. | 2023-02-14 14:52