leafo / sticky-kit

A jQuery plugin for creating smart sticky elements
http://leafo.net/sticky-kit
2.91k stars 521 forks source link

Let sticky element work inside overflow: scroll containers #47

Open tegola opened 10 years ago

tegola commented 10 years ago

Hello, Sticky-Kit relies on the body scroll values to work, but since my web app uses divs as main containers, the body never scroll.

Here's an oversimplified version of what I mean: http://jsbin.com/yitoheno/4

Is there a workaround for this? Maybe the plugin already accounts for this and I'm missing something?

Thanks!

frenetic commented 10 years ago

If you take a look at the Sticky-kit website, you will see that your statement isnt true, since the examples are working on scrolling divs. In this example you linked, it isnt working because you linked to the wrong file. At least, thats the error message being displayed by firebug. Check that and update this issue.

eddOrnelas commented 10 years ago

i have updated that example, but neither i has capable to stick on scrolling div (overflow:scroll), there is another way to do this?

regards

tegola commented 10 years ago

Sorry for the delay. I have updated that example too, and I can't get it to work anyway:
http://jsbin.com/yitoheno/8

chriscamplin commented 9 years ago

Having the same issue here & wondered if there was advice on a solution.

phr3qu3ncy commented 9 years ago

@frenetic if i understand it correctly, the examples on the website are in frames as opposed to divs.

also following to see if anyone has come up with a solution for this.

guyisra commented 9 years ago

+1

chrsalbert commented 9 years ago

+1, got the same request.

danschauder commented 9 years ago

+1, I'm having the same issue. Website examples look perfect, but they use iframes rather than divs. It would be awesome if this worked on divs with overflow:auto, but I haven't been able to make this work without relying on the body scroll

lafourmirouge commented 9 years ago

+1

joermungandr commented 9 years ago

+1

rosgzc commented 9 years ago

+1

tegola commented 9 years ago

I'm glad this has been acknowledged and set as an enhancement. Any estimate?

lucasstinis commented 9 years ago

+1

PrincessRebaula commented 9 years ago

hi, can you provide as a demo page, that is easier to understand instead? just a simple website page that use this plugin, a simple code that non pro can understand and just copy the code and just change the content.

metavoid commented 9 years ago

Hi, i've tried this trick with foundation 5 framework sidebar and custom offcanvas with wrapper for whole document with pseudo-scroll (overflow: auto). Change in your source code of sticky kit lib this lines. Change 'win' variable link from window object to your element with scroll. Then edit line 85-90 - code of spacer-wrapper so that its height would be equal the height of your main container (only if you have some bugs with the spacer element and it parent(spacer) gets wrong height). In this case also delete float attribute.

  1. win = $('YOUR_ELEMENT_WITH_SCROLL'); ....

if (spacer) { spacer.css({ width: elm.outerWidth(true), height: $('YOUR_MAIN_CONTAINER"]').height(), display: elm.css("display"), "vertical-align": elm.css("vertical-align") // DELETE FLOAT ATTR });

Optionally, I added location.reload() on resize event on scroll element, because iframes have wrong size after sticky recal method.

bawpcwpn commented 9 years ago

+1 on this.

Would a suitable solution involve being able to designate what the overflow container is as an option when initialising the plugin?

tegola commented 9 years ago

Actually, Waypoints Sticky plugin does this already. For now I've switched to that whenever possible.

tegola commented 8 years ago

Any update on this?

chrsalbert commented 8 years ago

I think it stuck. :(

ale24 commented 8 years ago

Is there any way to Stick inside a div instead of body or Let sticky element work inside overflow: scroll containers now?

tegola commented 8 years ago

@ale24 I'm not aware of a solution in Sticky Kit. As I already said, I've switched to Waypoints Sticky plugin.

ale24 commented 8 years ago

@tegola Do you have any examples with parallel scrolling sidebars in Waypoints Sticky plugin, cause I am not familar with this plugin at all?

tegola commented 8 years ago

@ale24 What you mean with "parallel scrolling sidebars"?

ale24 commented 8 years ago

@tegola I mean this http://codepen.io/anon/pen/oLQaJW

tegola commented 8 years ago

I do not have an example for something like that, sorry.

Keep in mind that Waypoints' Sticky plugin needs you to make the work for calculating the offsets, while Sticky Kit does them for you (which, I think, is the reason it still doesn't support sticky elements in divs).

tsnolan23 commented 7 years ago

Was there ever any update on this? I still can't use it on any div that isn't the body scroll event.

NewWorldOrderly commented 4 years ago

+1