vvo / lazyload

:bullettrain_front: Lazyload images, iframes, widgets with a standalone JavaScript lazyloader
https://vvo.github.io/lazyload/
MIT License
938 stars 158 forks source link

add onVisible callback #61

Closed willian12345 closed 9 years ago

willian12345 commented 10 years ago

add onVisible callback callback will be called when the element in viewport

it's useful to extend functionally outside. like this example in my project, I can do anything i want on 'elem'

window['lazyshow'] = lazyload({onVisible: function(elem){
            $(elem).addClass('fadeIn');
        }})```
vvo commented 10 years ago

Thanks for the PR.

I am sorry it's undocumented but already exists.

What you want to do is almost already feasible like this:

lazyload(ADOMElement, function onVisible() {
  // will be called when ADOMelement becomes visible
  // src will not be changed for you
});

You can also use vvo/in-viewport because this example is just an alias of in-viewport.

Do you think that's sufficient or do you really need this functionnality?

I think you could just use the standard lazyload and then if in the need for a callback on every element you can lazyload(ADOMElement, function onVisible() {});

If you really need this functionnality as the code is very small, we can integrate it, bust you need to add a test.

The test paragraph of the readme is pretty self explanatory and will be a good start.

Thanks.

willian12345 commented 10 years ago

Hi, Thanks for replied. I have read the lazyload.js and in-viewport.js Actually, I use the lazyload like your said in the beginning

lazyload(ADOMElement, function onVisible() {
  // will be called when ADOMelement becomes visible
  // src will not be changed for you
});

But i have to write the lazyload' logic in the in-viewport's callback And we often add some animations to the lazyload dom even we use any other lazyloader

Now i used your lazyload in my project In this page http://crapi.4gshu.com:8096/rongshuxia/excellent.html

The test, er.......