Pentiado / angular-lazy-img

Lightweight lazy load images plugin. Only 1kb after gziping. Pure JavaScript, only Angular as dependency.
MIT License
178 stars 66 forks source link

Kickoff on demand please.. #12

Closed PostImpatica closed 8 years ago

PostImpatica commented 8 years ago

Could we implement a method to kickoff your utility when we decide? Reason i ask is i have callbacks and stuff going on that takes a few before the page renders with the controls your program is expecting and therefore your control didn't work. I had to rig it with this code which i know is not the best method but at least it's working. Also, having the config try and load the element doesn't work for obvious reasons and this looked like issue #4 but after implementing the directive it didn't appear to do anything.

 angular.module('angularLazyImg').factory('LazyImgMagic', [
 '$window', '$rootScope', 'lazyImgConfig', 'lazyImgHelpers',
 function($window, $rootScope, lazyImgConfig, lazyImgHelpers){
 'use strict';

var winDimensions, $win, images, isListening, options;
var checkImagesT, saveWinOffsetT, containers;

images = [];
isListening = false;
options = lazyImgConfig.getOptions();
$win = angular.element($window);
winDimensions = lazyImgHelpers.getWinDimensions();
saveWinOffsetT = lazyImgHelpers.throttle(function(){
  winDimensions = lazyImgHelpers.getWinDimensions();
}, 60);
// ***********  H E R E    I  S    T  H  E    N  E  W    C  O  D  E
keepchecking();
function keepchecking(){
  var thescroll = document.querySelector('size-sensitive-div#scrollable');
  var whatever = angular.element(thescroll);
  containers = [whatever || $win];
  if(containers[0].context === undefined){
    setTimeout(function(){
      keepchecking();
    }, 200);  
  }
}

//containers = [options.container || $win];
PostImpatica commented 8 years ago

I added even more items and it started failing again. If i'm able to fix it in a way that maybe others can use i'll create a pull request. Either way feel free to close this issue, i'm thinking my issue is very specific to my case only but thought i'd share just in case.

PostImpatica commented 8 years ago

never mind. I forgot when using a directive you have to remove camel case and add dashes. Your module is working awesome!

Pentiado commented 8 years ago

:)