How to make Iscroll and Lazy Load jQuery plugins work together?

浪尽此生 提交于 2019-12-02 21:27:57

Today i had the same issue and i figured out that the scroll event is not triggered, which lazyload is listening to. So the only thing you have to do, is triggering the scroll event for your scroll container manually. I used the onScrollEnd callback from iScroll and did a

onScrollEnd: function () {
    $('div.scroll').trigger('scroll');
}

while $('div.scroll') is the container i used with iScroll

var scroll, container;

container = $('div.scroll');
scroll    = new iScroll(container.get(0), {
    bounce: false,
    onScrollEnd: function () {
        container.trigger('scroll');
    }
});

and this is what the lazyload method looks like

$('img.lazyload').lazyload({
    effect: 'fadeIn',
    container: $('div.scroll')
});

Cheers!

This may not be the best solution but since no one else has answered:

Try recalling the lazyload method on iscroll's onScrollEnd event. Something like this:

 new iScroll('wrapper', onScrollEnd: function() {$("img.lazy").lazyload()});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!