Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple items on change event #959

Open
ieraora opened this issue Jun 5, 2022 · 0 comments
Open

Multiple items on change event #959

ieraora opened this issue Jun 5, 2022 · 0 comments

Comments

@ieraora
Copy link

ieraora commented Jun 5, 2022

Hi. I try to implement Infinite Scroll - Loading JSON + Masonry.
I want run it in document.ready, but also when a dropdown change.
So, based to this example I group all js in a function..

function masloadinf(){
var $grid = $('.grid').masonry({
ect ect ect.
}

And use it in

$(document).ready(function(){
masloadinf();
});

and

$('#filtro_immagini').on("change",function(){
$('.grid').infiniteScroll('destroy');
$('.grid').masonry('destroy');
$('.infinite-scroll').remove();
masloadinf();
});

In document.ready, all good, no problem,
But whet i change dropdown, I see items group just two times,
If I chege also, I see items group three times, four times and other...

immagine

I undestand that error is here...

$grid.on( 'load.infiniteScroll', function( event, response ) {
console.log( response )
// parse response into JSON data
var data = JSON.parse( response );
// compile data into HTML
var itemsHTML = data.map( getItemHTML ).join('');
// convert HTML string into elements
var $items = $( itemsHTML );
// append item elements
$items.imagesLoaded( function() {
$grid.infiniteScroll( 'appendItems', $items )
.masonry( 'appended', $items );
})
});

In fact, if I don't use function masloadinf but copy code,
in document.ready all code and in on.change, commented
this code, all is fine.

I now ask what is the best solution to disable this code in on.change event
without copy all code, so keeping the function.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant