Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position fixed element inside scrollbar. #49

Closed
igorpreston opened this issue Dec 6, 2016 · 3 comments
Closed

Position fixed element inside scrollbar. #49

igorpreston opened this issue Dec 6, 2016 · 3 comments
Labels
FAQ Frequently Asked Questions

Comments

@igorpreston
Copy link

Hello,
Is there a way to make div element inside scrollbar container to stick always to top during scrolling?

Setting position: fixed, top: 0, left: 0, right: 0 didn't work.

@idiotWu
Copy link
Owner

idiotWu commented Dec 7, 2016

Since transform creates a new local coordinate system(W3C Spec), position: fixed is fixed to the origin of scrollbar content container, i.e. the left: 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:

const scrollbar = Scrollbar.init(elem, {
    // execute listeners synchronously to make sure they can be rendered at same tick
    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

@igorpreston
Copy link
Author

@idiotWu great, thank you very much, works perfectly!

@Jero786
Copy link

Jero786 commented Jan 23, 2019

@idiotWu thank you so much! you save me a lot of hours!!! :D

@idiotWu idiotWu added the FAQ Frequently Asked Questions label Nov 15, 2020
Repository owner locked and limited conversation to collaborators Jun 10, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
FAQ Frequently Asked Questions
Projects
None yet
Development

No branches or pull requests

3 participants