Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Styling for no/native/polyfilled position:sticky #33

Closed
wants to merge 27 commits into from

Conversation

pixelthing
Copy link

Hi, this is a modification specifically to allow the stylesheet to make layout decisions depending on the capability of the browser and outcome of the polyfill.

It allows devs to style elements for three eventualities:

  • No position:stickysupport is possible (results in no CSS class added to document)
  • Native position:stickysupport is available (results in fixedsticky-native class added to document)
  • Polyfilled position:stickysupport is available - or is chosen over native support (results in fixedsticky-polyfilled class added to document)

This is done by adding one class if native support is detected, and a second if the polyfill activates(1) an implementation of fixedsticky. If the dev chooses to substitute native implementation with the polyfill (by fixing the test and re-initialising), both the native and the polyfill classes are added.

I've tried to add and remove classes in a way consistent with how the existing code deals with fixedsticky-withoutfixedfixed, and to remove the class in destroy().

Lastly, telling the stylesheets that native support is available also means a dev might not need Modernizr (or at least a custom build - or grunt-modernizr - to compile a sticky test in). Bonus!

Notes:
(1) Note that just initialising the polyfill is not enough to add fixedsticky-polyfilled, the implementation does require the sticky element has a top:X or bottom:X that determines if it is activated or not. This meant packaging the top/bottom position test into a method, where it was a one liner before.

Craig Morey added 5 commits December 10, 2014 10:44
This gives dev (and their stylesheets) the possibility of modifying the
look of the page depending on if the result has no sticky support,
native support or polyfilled support.
If the purpose of `destroy()` is to remove the polyfill’s capabilities,
it doesn’t need to remove the `sticky-native` class, which could still
be relied on by the stylesheet.
Some browsers need the sticky element to have a `top:X` or `bottom:X`,
this now determines if `polyfill-active` is added to the document or
not.
@pixelthing
Copy link
Author

eek - just spotted a regression bug - line 145 rolls back commit c58fbea (nOOb mistake). Apologies.

Craig Morey added 5 commits December 10, 2014 12:50
allowing the sticky behaviour to activate at an offset other than the
container hitting the top of viewport. Config’d by adding a data
attribute to the fixed sticky element, e.g.
data-fixedstickyfudgetop="65" will start sticky behaviour 65px AFTER
the sticky container has hit the top of viewport.
@zachleat
Copy link
Member

I started to merge this to have a look but some of the tests are failing. Can you patch that up?

@pixelthing
Copy link
Author

Hi Zach, Thanks for giving it a go. I'm in the process of building a bigger PR with full sticky sidebar support http://codepen.io/pixelthing/pen/wBGwVK (I just need to check for memory and destroy() compatibility) so I could either patch this one up or get the bigger one ready, depending on whether you prefer the small steps or less PRs. Cheers!

Craig Morey added 13 commits December 22, 2014 12:47
If multiple sticky instances existed and one was “destroyed”, the
script would remove the scroll event binding from all instances and
lock any remaining sticky elements in their current position (either
initial, sticky or opposite). Now fixed.
@pixelthing
Copy link
Author

Sorry for the hassle - I've updated my fork with docs, demos and new features (that also happen to address some of the existing feature requests - although I know you're also working on them in a separate branch). As soon as I've gone through the tests and figured out what I need to do with them, I'll swap to another PR and kill this one.

@rickydazla
Copy link

@pixelthing as bonus I just tested your version and it seems to fix #44

@zachleat
Copy link
Member

zachleat commented Jun 6, 2017

Really sorry this never made it in. Closing all the PRs—this plugin is now deprecated: https://github.com/filamentgroup/fixed-sticky#-this-plugin-is-deprecated-

@zachleat zachleat closed this Jun 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants