Scroll to the top of pop up every time it's opened?

Hey there, I have a page where users can click on a home and it will bring up a pop up with that persons profile. Only problem I’m having is that when a user closes that pop up and clicks on another one it will stay at the position of where the user left the last one i.e middle of the pop up.

Does anyone know how I can make it so every time that pop up is clicked it will scroll to the top of of the pop up?

reset the popup each time on close or upon open set focus to the top element?

Scroll to and set page offset to 0? This will bring your view all the way to your top

Thanks guys. I’ve tried reseting the pop up like below but it’s not doing anything:

I’m unable to do the second suggestion as the user is viewing homes so needs to stay at the same position as they started rather than go to the top.

Don’t suppose anyone has an other ideas?

To clarify above, Set focus to top element in the popup

Thanks man, still can’t get it to work :frowning: I spoke to bubble and they said it had something to do with the custom code of the pop up:

The first part is so that the pop up is full width & height. The second part is to have a floating group within it for easy exit.

I don’t suppose you know what in the code is blocking this?

Try chatGPT

1 Like

Thanks mate! All sorted now, the issue was coming from the run javascript code, it was not resetting the scrolling position when the pop up was opened and closed. To solve it:

Amended code for when pop up is opened:
savedScrollY = window.scrollY;
let x = document.getElementById(“TA”);
x.style.position = “fixed”;
x.style.top = -savedScrollY + “px”;

// Reset the scroll position to the top
document.getElementById(“TC”).scrollTop = 0;

Amended code for when pop up is closed:
let x = document.getElementById(“TA”);
x.style.position = “absolute”;
x.style.top = “”;
window.scrollBy(0, savedScrollY);
document.getElementById(“TC”).scrollTop = 0; // This ensures the scroll position is reset when the pop-up is closed

This topic was automatically closed after 70 days. New replies are no longer allowed.