Pentiado / angular-lazy-img

Lightweight lazy load images plugin. Only 1kb after gziping. Pure JavaScript, only Angular as dependency.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stop loading all images in hidden div

mikej2017 opened this issue · comments

If I have two divs, one for view1 and another for view2 with "ng-show" and "ng-click" to toggle betwen them, if I set lazy-img tag on both, it will load all of the images from the second invisible div. If it entirely comment out that div it will only load the first 12 images as it should correctly. I checked the source of the hidden div (view2) and all of the img tags had the "src" attribute appended.

Is there anyway around this?

commented

I ran into the same issue. The way I solved it was by changing the isElementInView() to

function isElementInView(elem, offset, winDimensions) { var rect = elem.getBoundingClientRect(); var bottomline = winDimensions.height + offset; return elem.offsetParent && ( rect.left >= 0 && rect.right <= winDimensions.width + offset && ( rect.top >= 0 && rect.top <= bottomline || rect.bottom <= bottomline && rect.bottom >= 0 - offset ) ); }