I have a script that displays a button to scroll down when the user is not located at the bottom. I included the execution of this script in a page workflow. However, it seems that this doesn’t work. Do you have an idea ?
To note that :
There is no “scroll trigger” on an element but only at page level
I cannot use the “watch scroll” because the element must be dynamic.
I already ask the question on a Slack but I haven’t had a solution that works.
I’m not sure I grasp your use case completely. Could you record a short video that shows us what your page looks like, and explains what you’re trying to achieve?
@Joyce My need is quite simple : I want to display a button when the user is not at the bottom of a scrollable dynamique element (a chat). This button allows him to automatically scroll down. The same behavior as Whatsapp.
The solutions that were proposed to me did not work.
@Joyce The problem is that the size of my element is dynamic and therefore I cannot condition the display of the button depending on where I am in relation to the heigth of this element. This may work the first time but as the height increases there will be a lag.
Here is the explanation and a demo from a member of the Weweb community
Hello @Joyce
Can I find a solution to this problem with Weweb or am I heading straight into the wall?
However my piece of code is basic and it is pure JS…
How about displaying the button depending on where it is in relation to the bottom of the page or to the top of the element right below it on the page?
I’ve found a way to make the button appear when the user is not at the bottom of the div (when he scrolls up or when new message are added with Supabase Realtime for instance)
Made a short video to explain all of that better.
TL;DR
Scroll event listener to watch when the user scrolls up
MutationObserver to watch any changes in the DOM
I feel like it works well. Would love any feedback on that if there are downsides using that!
Had a look at your demo video.
I would suggest to try and isolate the different values to see where it is not working. My guess would be that you are not targeting the correct div to calculate its height or position.
Try putting some console.log()