If the sidebar is taller than viewport, you can temporarily scroll within the sidebar up until the bottom or top has been reached, in which case, it will become fixed again.
(I have done a script that sort of detects if the bottom of the sidebar has been reached (in which case it will become fixed) but I mess up when I already need to scroll back up. So I think I might be doing it wrong all along.)
Any help to achieve this would be greatly appreciated.
I have updated my plugin to solve some problems. For your case, the sidebar should have two layers of wrapper. One is used to handle the grid layout, and the inner wrapper is used to be a sticky element. This is important considering that this plugin will automatically add a .space-holder element right before the sticky element to fill the empty space when the sticky element changes its position from the initial position to be a fixed position, which usually affects the position of another element: