Forcing left panel to top after it closes

I can’t figure out how to get to the left panel to force it back to the top when it closes so the next opening shows it at the top.

Here’s what I’m doing right now:

$$(’.panel-left’).on(‘panel:closed’, function () {
console.log(“scroll: ” + $$(’.panel-left’).scrollTop());
$$(’.panel-left’).scrollTop(0, 0);
console.log(“did it”);
});

The event handler is working on every close. But scrollTop() is always showing 0 no matter where the panel has been scrolled to. Clearly, it’s not the .panel-left that has scrolled. What item under .panel-left has the scrolling?

Similarly, when the panel is closed, I’d like to force the next re-open to the topmost (back) level. How do I force things back to the topmost view of the panel?

I think you should find which node is scrolled. just check which one is much higher than the device height.

It should be “page-content”

$$('.panel-left').on(‘panel:closed’, function () {
  console.log("scroll: " + $$('.panel-left .page-content').scrollTop());
  $$('.panel-left .page-content').scrollTop(0, 0);
  console.log("did it");
});

Thank you for that suggestion - I tried it but it had no effect (adding .page-content). I’ll spend some time inspecting the nodes to find which part needs to have its scrollTop reset. If I find it, I’ll post it back for others. The old archive had a couple of questions about scrollTop like this too so it’s not something obvious for people starting out like me.

It depends on what you have in left panel. If you have there View -> Pages -> Page structure then it is should be $('.panel-left .page-content').scrollTop(0), if you have nothing else scrollable then $('.panel-left').scrollTop(0)

Or issue can be because when it is closed, it has display:none. In this case browser may not set scrollTop properly because the element is invisible and has no sizes. Then just change your logic to panel:open event:

$('.panel-left').on('panel:open', function() => {
  $('.panel-left').scrollTop(0);
  $('.panel-left .page-content').scrollTop(0);
})

That worked! Thanks so much.

So that’s the solution - you have to set the scroll on open, not close.

Thanks!