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

Trying to use angular-masonry with the lazyload plugin to load images.

Open gablabelle opened this issue 11 years ago • 5 comments

Hello,

I'm using angular-masonry on a project and it works fine.

screen shot 2014-05-27 at 09 58 41

But since I have lots of images I wish to lazyload images using the jquery plugin which works but the images overlap each others because they don't have width and height set.

screen shot 2014-05-27 at 09 58 24

So I guess I need to relayout masonry after the images are loaded in the DOM. I use the following directive to lazyload the images:

.directive('lazyload', function($timeout) {
    return {
      restrict: 'A',
      link: function (scope, element) {
        $timeout(function() {
          angular.element(element).lazyload({
            effect: 'fadeIn',
            effectspeed: 500,
            'skip_invisible': false,
            failure_limit: Math.max(angular.element(element).length - 1, 0),
            threshold : 1000,
            load: function() {
                angular.element(element).trigger('scroll');
            }
          });
        }, 0);
      }
    };
  })

and apply it to the following HTML markup:

<div masonry preserve-order load-images="true" class="stream row ng-cloak" ng-controller="PhotosCtrl">
    <article class="photo masonry-brick" ng-repeat="photo in photosList">
        <a no-click href="#">
            <img lazyload ng-src="images/transparent.gif" data-original="{{photo.url}}" alt="{{photo.title}}">
        </a>
    </article>
</div>

Any suggestions would be greatly appreciated. Please keep in mind that I not an experienced coder.

Many thanks for your time and help.

gablabelle avatar May 27 '14 14:05 gablabelle

@gablabelle did you solve this? I had the same issue. The problem was the images had no dimensions when the masonry plugin was loaded. My solution was to give the elements fixed dimensions even before the image is loaded. I think another solution could be having a "contentLoaded" event in the directive (as the imageLoaded one) that could be fired after the content is loaded and it is ready to be layouted.

pasine avatar Jul 08 '14 15:07 pasine

Kinda disappointing as the Readme says the plugin use imagesloaded to preload them.

grabbou avatar Sep 25 '14 11:09 grabbou

@grabbou it's long time ago, but did you include imagesLoaded.js lib?

hirbod avatar Apr 21 '15 19:04 hirbod

Can't remember. Switched to my custom isotope binding with manual imagesloaded method and that did the trick perfectly :)

grabbou avatar Apr 25 '15 15:04 grabbou

@gablabelle Hey gab, just wanted to thank you for your lazyload directive. Appreciate it, using it in my project.

kiempoturner avatar Sep 10 '15 02:09 kiempoturner