pklauzinski / jscroll

An infinite scrolling plugin for jQuery.
http://jscroll.com/
1.11k stars 563 forks source link

Problem with dynamic content #11

Closed jeedee closed 10 years ago

jeedee commented 11 years ago

I have an instance of jscroll binded to my element div#results. Using filters, my user may narrow the search which launches an ajax request that updates div#results. It seems jscroll does not work after the content has changed (even if I have an element with the selector).

I tried destroying jscroll and rebinding again once the content has changed but I had no success so far. Help?

Thanks!

lauth commented 11 years ago

There is a bug in the destroy method which prevent jscroll to be rebinded. The data is always binded to $e but in the destroy method it tries to remove it from _$scroll which can be $e or window.

To resolve it I added $e to the private vars :

_$e = $e,

then I changed the destroy function

function _destroy() {
_$e.removeData('jscroll');
            return _$scroll.unbind('.jscroll')
                .find('.jscroll-inner').children().unwrap()
                .filter('.jscroll-added').children().unwrap();
        }
pklauzinski commented 10 years ago

If the element is being replaced via ajax, then the original element you bound to no longer exists in the DOM, therefore you must reinitialize the jscroll behavior on the new element. Alternatively, you can bind the behavior by using delegation so that you can circumvent having to do this.