Best way to reset a scrollview to its start position

Hi, I have some buttons which tab through lists of items, each list of items gets put into a scrollview. Everything works fine but of course some lists are longer than others and so it would be nice to always at least reset the scrollview to its start position when selecting a new list of items.

Is there an easy way to do this?

Thanks

It’s not public API (I believe it should be and added a ticket for it), you have to set the scroll property with a pc.Vec2.

eg

this.entity.scrollview.scroll = pc.Vec2.ZERO;

Thanks. I tried:

 this.scrollView = this.app.root.findByName("ScrollView_New");//this.scrollView is the entity that contains the scrollview component
  this.scrollview.scroll = pc.Vec2.ZERO;//Sets scroll view to default

but I get an ‘undefined’ error.

this.scrollView = this.app.root.findByName("ScrollView_New");//this.scrollView is the entity that contains the scrollview component
this.scrollview.scroll = pc.Vec2.ZERO;//Sets scroll view to default

findByName returns an entity. So in the code above, it’s trying to set a pc.Vec2 on the property scroll on an entity object.

In my example, I’m using the property scroll on the scrollView component.

Change your code to the below.

this.scrollViewEntity = this.app.root.findByName("ScrollView_New");//this.scrollView is the entity that contains the scrollview component
this.scrollViewEntity.scrollview.scroll = pc.Vec2.ZERO;//Sets scroll view to default