I've been developing a site and taking advantage from the rather good jQuery Sticky Kit plugin. It operates by switching the position
property to fixed
and back when appropriate. Runs very smoothly in desktop and acceptably so in mobile.
Or at least it used to. iOS 9 comes with a new behavior: if the position
of an element changes from static
/relative
/absolute
to fixed
while the scroll animation is ongoing the element becomes invisible until after the scroll has come to a stop. Oddly enough the opposite change (from fixed
to whatever else) is performed without issues.
A working example can be found on the plugin's homepage. The black navigation bar ("Examples Reference") is supposed to be sticky. Originally it's static
ly positioned in mid-page. As you scroll down it becomes fixed
and (in iOS 9) disappears until scroll stops. Behavior in desktop browsers and iOS 8 is correct.
I was kind of hoping for the typical CSS workarounds: forcing a 3D transform, disabling backface visibility and the like, obscure proprietary properties, ... But nothing seems to work.
Are we about to forget "stickable" elements altogether now that it was working?
To force it work the same way as Mobile Chrome, you have to use position: absolute, height: 100% for the whole page or a container for your pseudo-fixed elements, intercept scroll, touchend, focus, and blur events. The trick is to put the tapped input control to the bottom of screen before it activates focus.
To see the effect of sticky positioning, select the position: sticky option and scroll this container. The element will scroll along with its container, until it is at the top of the container (or reaches the offset specified in top ), and will then stop scrolling, so it stays visible.
An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.
I had this same issue and was able to hack around it using the old "force a 3D transform" trick. Just set the element you are going to switch the position of to have a transform property of translate3d(0px,0px,0px)
. Make sure this is done before the position property is changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With