jquery isotope with infinite scroll and image prel

2019-07-09 04:26发布

I'm using jquery isotope and infinite scroll and want to use an image preloader

The image preloader I'm using is this: Image preloader

$('.image').preloader({
    loader: '/images_/icons/img_pre.gif',
    fadeIn: 700,
    delay : 200 
    });

It works perfectly on page one but then doesn't fire for the infinite scrolled items so I need to place this somewhere within the isotope callback, but where? Any ideas?

This is isotope callback code I use:

// call Isotope as a callback
function( newElements ) {
    $container.isotope( 'insert', $( newElements ) ); 
    $container.isotope({ filter: '*' });
}

2条回答
叼着烟拽天下
2楼-- · 2019-07-09 04:38

Walter Jr was close, but I'd already tried that. They key is order of the code, the preloader code has to come BEFORE the new elements are loaded, so:

function( newElements ) {

$('.image').preloader({
    loader: '/images_/icons/img_pre.gif',
    fadeIn: 700,
    delay : 200 
});

$container.isotope( 'insert', $( newElements ) ); 
$container.isotope({ filter: '*' });
}
查看更多
3楼-- · 2019-07-09 04:42

There is a loading property in isotope that is similar that you needs, but only for the entire next page, not an specific img element:

$container.infinitescroll({
    navSelector  : '#page_nav',    // selector for the paged navigation 
    nextSelector : '#page_nav a',  // selector for the NEXT link (to page 2)
    itemSelector : '.element',     // selector for all items you'll retrieve
    loading: {
        finishedMsg: 'No more pages to load.',
        img: 'http://i.imgur.com/qkKy8.gif'
      }
    },
    // call Isotope as a callback
    function( newElements ) {
      $container.isotope( 'appended', $( newElements ) ); 
    }
  );

Perhaps you can try calling the preloader with something like this:

// call Isotope as a callback
function( newElements ) {
    $container.isotope( 'insert', $( newElements ) ); 
    $container.isotope({ filter: '*' });

    $('.image').preloader({
        loader: '/images_/icons/img_pre.gif',
        fadeIn: 700,
        delay : 200 
    });
}
查看更多
登录 后发表回答