What is AP.scrollPosition and how to use it?

While researching whether there is any way to implement a sticky toolbar inside a Confluence macro iframe, I came across AP.scrollPosition. However, calling AP.scrollPosition.getPosition(console.log) or AP.scrollPosition.setVerticalPosition(0, console.log) does not do anything when called by a macro. Where does this work and how exactly to use it?

Dear @candid. I had the same issue and gave up. It seems that AP.scrollPosition seems to be limited to generalPages based on this article.

Thank you, that’s good to know. This is a pity, since this functionality seems particularly unnecessary on general pages, where the scrolling behaviour can be handled inside the iframe.

Dear @candid : just for curiosity: what are you trying to achieve? I was looking into that because I wanted a link from inside one dynamic content macro to another one. As the Ids Confluence creates for the iframes holding the macros are random we are not able to do so… One of our apps (Simple Cites) is still based on Static Content Macros which we would like to change but currently can’t without loosing the link functionality.

I would guess that it would be possible to scroll to a macro using scrollIntoView() on a DOM element in the macro that you want to scroll to, such as its body. From your source macro you can either access the DOM of the target macro directly by iterating through parent and finding the right frame, or you can us AP.events to send an event to the target macro to tell it to call scrollIntoView().

My use case is different: My macro contains a potentially very long table with a toolbar on top. The toolbar should be sticky, so it should be visible no matter where in the table you currently are. Currently I’m achieving this by setting an arbitrary max-height on the table, hoping that it will fit on the user’s screen, and making it scrollable using overflow: auto. But this is not so nice because it means that there are nested scrollbars on the page, and on a large screen it looks weird. I was hoping to be able to have the macro have the full height of its content and simulate a sticky scrollbar by using AP.scrollPosition to determine the current scroll position on the page.

1 Like

I never came across scrollIntoView but it seems to be exactly what I was looking for. Thank you very much for the hint.