Giter Club home page Giter Club logo

fixed-sticky's Introduction

Fixed-sticky

🚨🚨 This plugin is Deprecated 🚨🚨

In our own designs we use sticky sparingly and as an enhancement, which means that fallback positioning behavior is acceptable. With native browser support for position: sticky expanding, we must weigh the diminishing cross-section of browsers that require this polyfill against this plugin’s own maintenance costs. Therefore, we’ve decided that now is the right time to retire fixed-sticky. The previous documentation can be found at v0.1.7. NPM will report a deprecation warning. If you want to maintain a fork of this package, send me a message (@zachleat on Twitter) and I’ll add a link to it below. Thank you!

Filament Group

  • ©2013 @zachleat, Filament Group
  • MIT license

Great alternatives

Native position: sticky

The most overlooked thing about position: sticky is that sticky elements are constrained to the dimensions of their parent elements. This means if a sticky element is inside of a parent container that is the same dimensions as itself, the element will not stick.

Here’s an example of what a sticky element with CSS top: 20px behaves like:

Scrolling down. The blue border represents the dimensions of the parent container element. If the element’s top is greater than 20px to the top of the viewport, the element is not sticky.

Scrolling down. When the element’s top is less than 20px to the top of the viewport, the element is sticky.

Here’s an example of what a sticky element with CSS bottom: 20px behaves like:

Scrolling up. Not sticky.

Scrolling up. Sticky.

Demos

Native position: sticky Caveats

  • Any non-default value (not visible) for overflow, overflow-x, or overflow-y on the parent element will disable position: sticky (via @davatron5000).
  • iOS (and Chrome) do not support position: sticky; with display: inline-block;.
  • This plugin (and Chrome’s implementation) does not support use with thead and tfoot.
  • Native sticky anchors to parent elements using their own overflow. This means scrolling the element fixes the sticky element to the parent dimensions. This plugin does not support overflow on parent elements.

fixed-sticky's People

Contributors

bbodenmiller avatar dfurnes avatar greenkeeperio-bot avatar jefflembeck avatar jimmynotjim avatar jonykrause avatar katranci avatar lipsumar avatar mattbrundage avatar mattdsteele avatar tbranyen avatar web20opensource avatar wilto avatar zachleat avatar zhangyijiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fixed-sticky's Issues

Clearer instructions on how to use please

I've failed every time I've tried to use this plugin and I swear I'm an experienced web developer and not a complete idiot. Results are mixed but never quite what I'm expecting. DOM structure seems to matter a lot here. Also the plugin doesn't seem to account for margins and paddings in some cases?

Doesn't Work With #Hash

Anytime I load a page with a hash in the location, I don't see the "fixedsticky-on" class being added in Chrome.

Flickering Effect on mobile chrome and other mobile Browsers

Hello,

i want to fix a element to the top when it reaches the top by scrolling. At the beginning it is not on the top.

It works really fine on Desktop Chrome and Firefox.

But on mobile Chrome i get a flickering effect. Its like it is set to fixed a few pixels too late.

Any Suggestions for me?

Kind Regards, Domenico Iavicoli

Support left/right position

Hi,

This is a great polyfill. However, it only supports top/bottom position values, is there any plan to support left/right as well?

not working at all?

Scripts & css loaded, No errors..?

http://ggdev.jynk.net

$( '#nav__scrollto' ).fixedsticky();

<nav id="nav__scrollto" class="section_scrollto--nav top fixedsticky"> <?php for($x=0;$x < count($section_list);$x++){ ?> <a class="nav-link" href="#<?= $section_list[$x] ?>"><span class="nav-link__label"><?= $section_titles[$x] ?></span><span class="nav-link__dot"></span></a> <?php } ?> </nav>

.fixedsticky { top: 0; }

Broken in Browserify (shimmed) (this != window)

Simple as it says. this is passed into the fixedsticky.js IIFE. Browserify sets this to undefined in the context of each compiled module.

This can be worked around by wrapping the require in (function (){...}).bind(window).call(), but if you're using something like Traceur (where imports are statements, not expressions) it falls apart.

It should be window, not this.

destory method?

Hi, I want to temporarily destroy the plugin, how can I do that?

plz advise. thx!

No AMD support?

Tried this with yepnope.js (included with Modernizr) and doesn't seem to work.
Is AMD supported in any way or is this an isolated case? If so I'll investigate more to see if I can help anyway.

Nice work, by the way!

no jquery dependency?

hi, I used this plugin quite often, but recently I start to use react, as you know, jquery is not so important when using with react.

I don't want to increase my size of js files, so is it possible use this plugin without jquery dependency?

plz advise.

thx.

A way to add styles to an element only when it's currently sticky?

What I imagine to be a common use case is adding styles to an element when it's sticky, for example a box shadow to make it appear above the contents scrolling beneath it.

While this is easy when the polyfill is in effect, since it toggles the fixedsticky-on and fixedsticky-off classes, it's not possible when position: sticky has native support, as far as I know.

For browsers that support native sticky position, I think there is no property available on the DOM node object that tells you if the element is in a sticky or non-sticky state, so good old fashioned scroll event listeners would be necessary. It would be great if this library could still toggle a class on the element to allow this kind of styling even when there is native sticky support. Thoughts?

Browserify support?

This would be great to use within browserify. Is that integration in the road map?

Scrolls to top once activated

When the plugin is activated it scrolls to top of page. Since it needs to wait for the load event (some resources are causing issues for calculating positions) then the user often scrolls a bit before the plugin loads, meaning the user is being bugged by this.

Check out http://blog.tattoodo.com/ for an example. The newsletter widget in the right sidebar is supposed to be sticky. Open console and fire: $(window).trigger('scroll.fixedsticky') to see the effect.

Browser: Chrome

Support applying to `position: absolute`

Fixed-sticky applied to an absolutely positioned element works great in Chrome, but

  • in Safari, fixedsticky-on is never applied
  • in Firefox, fixedsticky-on is immediately applied and never removed

Container-based scroll

Hi, I was wondering if it's possible to make the plugin work when the sticky elements are inside a scrollable container instead of the body.

E.g. in a mobile app I'm creating, the nav bar is fixed at the top and the content container has position:fixed; top:44px;
The user scrolls the content in it, not the whole page. My sticky elements are inside this container.

Thanks,
Luca

Is the fixed DIV expected to lose its width in Chrome?

I use Bootstrap 3 and am experiencing the exact same issues as I would when using position:fixed on on of my columns when using this plugin.

As I scroll the browser, when the fixing/stickying kicks in my div width changes. I just want to keep it the same width. This is happening in Chrome but not Firefox.

It also only works when applying the ID and class to the column itself, and not a child div of the column:

Works:

<div id="fixedQuoteSidebar" class="col-md-4 hidden-sm hidden-xs fixedsticky" >

        <div class="alert alert-success paddingtop5 text-center">
        </div>
</div>

Does not work:

<div class="col-md-4 hidden-sm hidden-xs " >

    <div id="fixedQuoteSidebar" class="fixedsticky">
        <div class="alert alert-success paddingtop5 text-center">
        </div>
   </div>

.fixedsticky-on element activates way above parent element

.fixedsticky-on is being called up to 700px above the parent container of .fixedsticky-on. I've tinkered with setting a fixed height and width on the parent container and .fixedsticky element. If the width of the browser is changed, fixedsticky-on is called at different times, all still way above the target container

Check out the problem here: http://www.meventi.de/event-6634-17727-Ballonfahrt-Aachen.html. Make sure your browser is small tablet size or mobile. fixed-sticky is deactivated in larger views.

before
screenshot_2015-09-18_12_25_41

and here's where everything goes crazy
screenshot_2015-09-18_12_25_48

Note:
This problem does not happen when 'position:sticky' is working.

@zachleat @jefflembeck @jonykrause @wshaver and anyone else

Scroll performance suffers a bit

If I scroll really quickly with a fixed/sticky element on the page, the repaint gets a little choppy. I understand it's a balance between having a smooth transition when a sticky element snaps into place and having a smooth scrolling animation for the rest of the page, have you considered adding a debounce option?

Not working with jquery.mobile on mobile device

I tried working your script with jquery mobile but it seems to be not compatible with it. I tried searching by myself by building custom package but I don't found anything.

However in my desktop web browser it's working fine but in ios (safari and chrome too) the DOM element not sticky ... I don't know what happens :/

Can you help me ?
Thank's

Support for overflow

Support for overflowing would be very useful,
especially when height: 100% has to be used on the parent (html, body) elements.

Thanks.
With best regards

Request: table-cell support

Hi,

I was just wondering if this is planned at all or if you consider it not being worth adding support for.

Basically, a reason one might use table-cell is to ensure unconditional equal heights on elements as opposed to inline-block. Say for eg. a main content area and a sticky sidebar to go with. Here's a JSFiddle of a similar markup I'm talking about where fixedsticky doesn't work:

http://jsfiddle.net/RXFRD/

I hope you can understand the use-case and hopefully in the near future implement some sort of support for it or alternatively maybe some markup to accomplish similar layouts where fixedsticky would work?

Best regards,
Rayken

need a way to force position recalculation

When using angular, it would be fantastic to be able to use fixedsticky() on an element, then forget about the fixedsticky api and instead use ng-hide or ng-show bindings in order to control the visibility of the sticky menu. Unfortunately, this leads to some unfortunate behavior because while the sticky is hidden (but not 'destroy'ed it doesn't calculate position quite correctly.

Is there a function in your api to force a positional recalculation? If not, would you be receptive to a pull requests which adds a simple feature along those lines?

Stick To Top of Parent?

Do you think it would be possible to stick to the top of the parent and not just to the top of the window? I'll start playing with the code, but thought I would see if anyone had tried yet.

Container doesn't support padding

Take this JS Bin: http://jsbin.com/rumahewupu/2 (It uses the code from the issue-28 branch to allow for the bottom transition case.)

The problem is that the sidebar scrolls to the very end of the container element even though the container has a bottom padding. Safari 8 respects the padding.

Does not work correctly anymore in Chrome 52

Hi there,

The polyfill does not work correctly anymore on Chrome 52.

It starts to fix the element on top when you scroll down, but does not release it when you scroll up.

What I found out so far is that the polyfill uses jquery's css-function to get the top and bottom-values and check if these values are "auto" (see https://github.com/filamentgroup/fixed-sticky/blob/master/fixedsticky.js#L93)

the css-function of jquery uses the browsers getComputedStyle-function and this function now (correctly) returns the computed value, not the actual value that is set in the stylesheet.

So this line above (https://github.com/filamentgroup/fixed-sticky/blob/master/fixedsticky.js#L93) will always yield position = {top: true, bottom: true} .

Later isFixedToBottom will return true because of this and this leads to the problem.

I don't know how to actually fix it yet, but maybe someone has an idea.

initialOffset incorrectly calculated

Seems like initialOffset is incorrectly calculated in some places.

            if( !initialOffset ) {
                initialOffset = $el.offset().top;

If $el.offset().top returns zero then this check will keep running until it finds something non-zero and end up in an incorrect state.

            if( typeof initialOffset === 'undefined' ) {
                initialOffset = $el.offset().top;

Seems to correct the issue.

Polyfill doesn’t get well along when used with floats

So, one issue I experienced during testing was that the polyfill did not reflect my original positioning of the target element that should have sticky position. The element has position: relative (it might be the root cause that this is overwritten with static by the polyfill), and had also a float: right set. I’m not entirely sure if the float caused problems by itself or if it’s only the position mode. Therefore I file this issue.

elements disappear from view, rather than scroll out of view

Looking at the demo (as well as my own test implementation) with Chrome 35 OS X, when an element switches from .fixedsticky-on to .fixedsticky-off it just out of view, but in sticky supporting environments it will be stuck to the bottom of the container and scroll out of view.

This jump is particularly jarring with taller elements (for example, a sticky sidebar rather than the short demo header), a behavior I can't have this happen in my particular project.

Example: scroll down in the demo watch the behavior of the red "Fixed to viewport top A." banner (#top-a) in demo when the first grey .container begins to leave view.

Potential Solution: Perhaps rather than using the "off" mode, having an "end" mode, setting position:absolute; bottom:0 (or calculated top) so the .fixedsticky item doesn't go poof?

Publish to npm registry

It would be helpful publishing this to npm registry,
a package.json is already there anyway.

Thank you and
with best regards.

Documentation on overriding native position:sticky

Hi, I'm not sure if this is due to changes since the docs were created, but the bit that tells you how to override the native sticky implementation appears to be incomplete, it now needs fixedsticky to be reinitialised otherwise the init() function is never completed. So I think it should be:

FixedSticky.tests.sticky = false;
FixedSticky.init( $('#your-element') );

z-index not respected in polyfill

Thanks for this great project!

Quick question: with native sticky positioning, it looks like z-index is respected even when the element is unstuck. Mozilla docs say "Sticky positioning is a hybrid of relative and fixed positioning.", both of which respect z-order.

However, in the polyfill implementation, it toggles between static and fixed positioning (rather than relative and fixed), and the static positioning ignores z-index.

So, if you have a sticky element positioned on top of a background element, the native version will show it correctly, but the polyfill will only show it when stuck.

Is there a reason for using static in the polyfill rather than relative?

window resize causes problems with sticky elements with floats inside

i am having some problems with fixedsticky.js in fallback browsers when the browser is resized.

The first problem is when a sticky element contains floats inside that stack differently depending on the layout width/height. It seems like it has something to do with the recalculating the height of the fixedsticky element?

The other problem is also related to resizing, my bottom div with fixedsticky, fails to stick after resize (this element also contains floated elements inside).

Is there a way of refreshing the plugin on window resize?

Thanks

Ps: Using the latest OSX Mavericks with latest Chrome, Firefox and Opera.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.