Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isotope & Infinite Scroll with manual triggering

I'm using Isotope plugin with Infinite Scroll plugin. With the default settings Infinite Scroll automatically triggers loading new elements which is fine, however, I would rather have a button "Load more images".

I'm only missing a small piece of code that will get new elements from Infinite scroll that I can pass to isotope INSERT function. Please see my comments below in code:

// initialize infinite scroll
$container.infinitescroll({
    navSelector  : '#paging',    // selector for the paged navigation 
    nextSelector : '#paging a',  // selector for the NEXT link (to page 2)
    itemSelector : '.col',     // selector for all items you'll retrieve
    loading: {
        msgText: 'Loading...',
        finishedMsg: Loaded all!',
             }
    } // <-- NOTE that we do not use callback function here!
    );


$(window).unbind('.infscr'); 

$('#paging a').click(function(){

// NEED CODE HERE TO GET NEW ELEMENTS FROM INFINITE SCROLL AND PASS THOSE ELEMENTS TO $container.isotope('insert', $(newElements)); 

}); 
like image 255
Antonio Avatar asked Sep 13 '12 14:09

Antonio


People also ask

What is an isotope simple definition?

What is an isotope? An isotope is one of two or more species of atoms of a chemical element with the same atomic number and position in the periodic table and nearly identical chemical behavior but with different atomic masses and physical properties.

What is an example of isotope?

The atoms belonging to the same element, having same atomic number Z, but different mass number A, are called isotopes. For example, carbon-12, carbon-13 and carbon-14 are three isotopes of the element carbon with mass numbers 12, 13 and 14 respectively.

Is an isotope an atom?

Isotopes are atoms of the same element that have different numbers of neutrons but the same number of protons and electrons. The difference in the number of neutrons between the various isotopes of an element means that the various isotopes have different masses.

What is an isotope GCSE?

Isotopes are forms of an element that have the same number of protons but different numbers of neutrons. There are three isotopes of hydrogen: hydrogen, deuterium (hydrogen-2) and tritium (hydrogen-3): Carbon has three isotopes: 126C, 136C and 146C.


1 Answers

The infinite scroll plugin actually offers a "manual-trigger"-behavior to do just what you're after.

Include manual-trigger.js after jquery.infinitescroll.js, tell infinite scroll to use the behavior by passing behavior: 'twitter' when calling the plugin, then just call Isotope as a callback as demonstrated in Isotope's demo for Infinite Scroll:

$container.infinitescroll({
  navSelector  : '#paging',
  nextSelector : '#paging a',
  itemSelector : '.col',
  behavior: 'twitter',
  loading: {
      msgText: 'Loading...',
      finishedMsg: 'Loaded all!'
    }
  },
  // call Isotope as a callback
  function( newElements ) {
    $container.isotope( 'appended', $( newElements ) ); 
  }
);
like image 117
fk_ Avatar answered Sep 17 '22 18:09

fk_