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

Appended and Prepended with ImagesLoaded #560

Open
nasif-co opened this issue Oct 8, 2021 · 0 comments
Open

Appended and Prepended with ImagesLoaded #560

nasif-co opened this issue Oct 8, 2021 · 0 comments

Comments

@nasif-co
Copy link

nasif-co commented Oct 8, 2021

Not really a bug but rather asking for the correct way to do something in particular: In certain moments I'm trying to append/prepend items to my packery grid. However, I'd like to first load all the images in those items and once that is done, append/prepend them visually to the grid. I tried this:

$grid.append(items);
$grid.imagesLoaded( function() {
  $grid.packery('appended', items);
});

Because I thought the first line $grid.append(items) did not trigger any visual changes, but apparently it does; there is a brief moment in which the new items overlap with the others. I suspect this happens in the time between the first line running and the layout triggered by imagesLoaded taking place.

Then, I attempted to use the 'addItems' method first and then run 'layoutItems' but now it seems the items are not being added at all:

//newItems is a jQuery object that works as expected using $grid.packery('appended', items); but not here.
$grid.packery('addItems', newItems);
  let addedItems = $grid.packery( 'getItems', newItems );
  $grid.imagesLoaded( function() {
  $grid.packery('layoutItems', addedItems, false);
  });
}

Also if I managed to get this method to work, it would only append the items, I can't see how I could use it to prepend them.

Any suggestions are greatly appreciated!

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