Scrolling up in a container using code

I have a comments section made with a repeater in a vertical scroll container.
If a new comment is added while scrolled down, the comment populates at the top but is not visible.

Is there a way to use code to scroll up in a container after submitting a new item into the repeater?

(Using an anchor doesn’t work in this scenario as it seems that only works for scrolling up the page)

Here’s the docs for scrollTo scrollTo - Velo API Reference - Wix.com

I also think an anchor would work if it’s the top of the section the repeater is contained in and the repeater is the first item. What do you think?

Hi, thanks for the input!

Unfortunately, that doesn’t work - the repeater is in a box that’s scrollable (because this is a popup window and I keep the box at a fixed height and the repeater then can be scrolled through in the box).

Even if it weren’t a popup window, if I put an anchor in the section it would keep the repeater the same and scroll up, but I need the repeater itself to scroll up. Hope that makes sense.

One solution I found is to change the filter of the dataset after submission and then bring it back to the original filter, which forces the repeater to repopulate itself with the first item on top. This makes the process a bit slow but it’s better than nothing ( .refresh() doesn’t do the same trick).

1 Like

Ah apologies! I misunderstood the issue you were trying to solve. I’m glad you found a workaround even if it is not performing ideally. I will think on this a bit more if there is a better solution for you and others here may weigh in as well

In this case, would be nice to have something like…

$item(‘#aaa’).scrollto() :upside_down_face:

Yes, a → scrollBy(), or a —> scrollTo(), will not work in this case.

ScrollBy(), which is dedicated to the page itself (window) and scrollTo() which can control elements on the page → like repeater ITSELF, but still not capable to scrollTo() elements → INSIDE-REPEATER.

A nice idea for Wix to integrate such a function for the repeater.

I see your workaround as a simple solution, but it’s not the only one.

The hard one would be to generate your own specific repeater, inside an HTML-Component or CUSTOM-ELEMENT.

Not long ago there was already a post about such an opertunity you can create by your own.

The repeater-API should get this additional function to be able to interact with the scroll-wheel of the mouse (to be more precise → the ITEMS ← inside repeater should get such a functionality) → this would make it much easier to interact with the repeater.

QUESTION: What we are doing all the time inside an repeater? → exactly → SCROLLING!

The following post will give you maybe the right idea of how to generate your own REPEATER…

1 Like

Maybe you want to recode this one for your own purposes, so you have already some kind of BASIC-REPEATER…

About design and functionality, decide on your own what you want to implement and how your repeater has to behave and how to handle the incomming data.

1 Like

I will pass this feedback along to the team that this would be nice to be able to use the scroll API with repeaters.

And thank you for offering the solution of a custom element as another option!

2 Likes

Thank you for the suggestions! What you’re saying also reminded me of the fact that you can scroll to a custom element without the scroll animation.

The main reason I wanted to use a popup window was to be able to immediately go to the comments section, which isn’t possible with the regular scroll with animation. So now I might use a repeater in a regular section without a box, and there will be no need to scroll within the box.

This is why i am always telling to show your whole setup.
It always depends of how you setted-up and structured your page/site.

There are always several different ways of how to get your aim.

Anyway, the suggested new implementation for the repeater, would open new possibilities and is a very often questioned feature. Despite everyone who has a wix-website will to 90% use a REPEATER.