angular-masonry icon indicating copy to clipboard operation
angular-masonry copied to clipboard

preserve-order AND imagesloaded

Open wordlink opened this issue 11 years ago • 3 comments

Looking to make preserve-order AND imagesloaded work together. So imagesloaded is used, but it waits for the previous images to be loaded in order before displaying (with a timeout option per load).

wordlink avatar Oct 12 '14 07:10 wordlink

I found one solution to this general problem with masonry and angular that seems to work for me but is very situational.

If your images all have the same aspect ratio then you can use:

.image{ background-size: contain; background-repeat: no-repeat; width: 100%; height: 0; padding-top: 46.73%; } padding top is the aspect ratio in percent of your image. (width/height*100).

on the div that should normally contain the image, and set the backround image url dynamically.

elgubbo avatar Feb 18 '15 01:02 elgubbo

@elgubbo for this "solution", you don't need imagesloaded

JohnnyTheTank avatar Nov 28 '15 12:11 JohnnyTheTank

@elgubbo Thank you for this solution. I was stuck on this the whole evening and I am glad I saw your post. The good old css to the rescue. Inspired by you, I now have the following set-up:

CSS:

.image_aspect_ratio {
  background-size: contain;
  background-repeat: no-repeat;
  width: 100%;
  height: 0;
  padding-bottom: 75%;
  position: relative;
}
.image_aspect_ratio > img {
  position: absolute;
}

HTML:

<div class="image_aspect_ratio">
   <img ng-src="" />
</div>

I calculated the aspect ratio percentage with this formula:

Height / (width / 100)

@JohnnyTheTank You are right. I dont need the imagesloaded with the above solution.

I am glad it works now!

Mr-Anonymous avatar Dec 29 '15 13:12 Mr-Anonymous