somewebmedia / hc-sticky

JavaScript library that makes any element on your page visible while you scroll.
https://somewebmedia.github.io/hc-sticky/
MIT License
463 stars 115 forks source link

How to use reinit method? Always get "reinit is not a function" #52

Closed justanotherco closed 6 years ago

justanotherco commented 6 years ago

Hey there,

Trying to run the reinit method but can't understand how it works. Could you please look at this non-working pen and if possible point out what's wrong with it? The console always says reinit is not a function

https://codepen.io/anon/pen/xzavRw?editors=1111

Thanks in advance

justanotherco commented 6 years ago

Fixed with .data('hcSticky').reinit();

somewebmedia commented 6 years ago

@justanotherco Actually it's a bug, it should be attached to the element directly. Thanks for noticing this, I'll fix it.

somewebmedia commented 6 years ago

My bad, it shouldn't be on the element.

somewebmedia commented 6 years ago

@justanotherco I've updated the plugin so now you can call the methods properly like this:

var $sticky = $('#element');

$sticky.hcSticky({
  stickTo: '#content'
});

// Call the refresh method
$sticky.hcSticky('refresh');
justanotherco commented 6 years ago

That's great news, thanks for the hard work! Out of curiosity, are there any benefits to using it that way instead of data('hcSticky') apart from the more standerized syntax?

somewebmedia commented 6 years ago

In case I ever change the way the methods are attached to the jQuery object, by using standardised syntax you ensure that everything will continue to work properly.