bbarakaci / fixto

A jQuery plugin for sticky positioning
MIT License
217 stars 57 forks source link

Refresh on dynamic callback doesn't work #14

Closed WillMuijrers closed 9 years ago

WillMuijrers commented 10 years ago

Great plugin, love it! I'm using infinite scroll to dynamically add content to my page. When the page loads, fixTo works just fine:

// fixTo init $('article.nieuws aside').fixTo('article.nieuws', { zIndex: 10, mind: '#header', top: 60 });

After the new content is loaded by infinite scroll, the plugin stops working on the new elements. Using refresh or start doesn't work. I think this has to do with fixTo being called on the same element twice. console: Uncaught TypeError: Cannot read property 'offsetHeight' of undefined

bbarakaci commented 10 years ago

Don't know what is going on but here is a guess:

On page load you run fixto on some elements and it works on them. Then you load some new elements, you dont run fixto on them so it does not work on them. Refresh does not adapt to new elements, it adapts to layout changes. You can try to init fixto on new elements or you can destroy the current ones and apply again on all of them.

WillMuijrers commented 10 years ago

Thanks for the quick reply! Regrettably, that doesn't work. The console says: Uncaught TypeError: Cannot read property 'call' of undefined or Uncaught TypeError: Cannot read property 'offsetHeight' of undefined It looks like he cant init the callback anymore, but why?

bbarakaci commented 10 years ago

i used both techniques in this fiddle. Seems to work.

http://jsfiddle.net/3k6aj/

Pressing on the buttons will add new elements and attach fixto on them.

If you prepare a fiddle of your case i could debug it.