-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Added spacingTop feature to sticky plugin. #6536
Conversation
By default sticky element get sticked at the top of the screen without any gap. This commit allows to add it in options object: ```js $('#element').sticky({ container: '#container', offsetTop: 25 }); ```
@vovayatsyuk offset could be different for desktop & mobile, so would be great to calculate it dynamically. |
I can extend this functionality to allow to pass a function as a offsetTop parameter. |
Hi, I just realized that it's better to call this parameter as a
What do you think? |
It'd be better to tend towards the more generic solution, which is to define the way an element is being displayed in sticky mode with a CSS declaration. Unfortunately, current implementation doesn't provide any specific class when an element becomes fixed. Could you please add one? E.g.: options: {
stickyClass: '_sticky'
},
_stick: function () {
//...
this.element.togglClass(this.options.stickyClass, isElementFixed);
} |
Yes, I thought about this too, and wanted to create another pull request with css solution. In order to keep current implementation, I though it could be defined optionally: $('#element').sticky({
container: '#container',
stickyClass: '_sticky' // empty by default
}); Implementation example: if (this.stickyClass) {
this.element.toggleClass(this.stickyClass, (offset > 0));
} else {
this.element.css( 'top', offset );
} p.s. However, the most wise solution is to use some popular third-party library instead of own sticky script. Don't you think so? |
Oh, I see what you wanna do here. Well, I meant to add this flag merely as a state indicator and to retain current positioning via inline styles. As you've mentioned, this way we can avoid breaking changes.
I hear you. To be frank, I'd rather replace it with a polyfill of |
Oh, I see. Yes, state indicator could resolve PR subject and gives a lot more. I think we can close this PR in favor of another one with class name indicator. |
@vovayatsyuk thanks for you contribution. Looking forward to get new PR created. |
Sorry, my mistake. Class name indicator is a great thing and should be added too, but it doesn't give me an My use case is:
Can you reopen this PR? |
[Arrows] MC-23915: Revert 23915 because it caused static tests failure
By default sticky element get sticked at the top of the screen
without any gap. This commit allows to add it in options object: