Position fixed element inside scrollbar. #362
-
Hello, Setting position: fixed, top: 0, left: 0, right: 0 didn't work. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
Since So it's recommended to put your fixed element outside the scrollbar contents, or you may need to register a scroll listener and apply offsets to the fixed element. FYI: const scrollbar = Scrollbar.init(elem, {
// execute listeners synchronously to make sure they can be rendered at same tick
// this is only needed in v7.x
syncCallbacks: true,
});
scrollbar.addListener(({ offset }) => {
fixed.style.top = offset.y + 'px';
fixed.style.left = offset.x + 'px';
}); A working demo is here: http://jsbin.com/tuqafof/edit 06/04/2022 Edit |
Beta Was this translation helpful? Give feedback.
-
@idiotWu great, thank you very much, works perfectly! |
Beta Was this translation helpful? Give feedback.
-
@idiotWu thank you so much! you save me a lot of hours!!! :D |
Beta Was this translation helpful? Give feedback.
-
Perfect hack ! Thanks a lot!! |
Beta Was this translation helpful? Give feedback.
-
If your SS is placed in #demo, you can add the following style to the #demo #demo{
overflow: auto; height: 100vh;
}
.your_fixed{
position:fixed;
} |
Beta Was this translation helpful? Give feedback.
-
thnx idom |
Beta Was this translation helpful? Give feedback.
Since
transform
creates a new local coordinate system(W3C Spec),position: fixed
is fixed to the origin of scrollbar content container, i.e. theleft: 0, top: 0
point.So it's recommended to put your fixed element outside the scrollbar contents, or you may need to register a scroll listener and apply offsets to the fixed element.
FYI:
A working demo is here: http://jsbin.com/tuqafo…