bbc / Imager.js

Responsive images while we wait for srcset to finish cooking
Apache License 2.0
3.84k stars 224 forks source link

Check if image is visible #95

Closed tdwesten closed 9 years ago

tdwesten commented 10 years ago

I have a responsive layout with images hidden on mobile and visible on a tablet/desktop. by default all the images are loaded. So on mobile also the hidden images are processed and loaded bij Imager.js. A extra check if the div/img element is visible would be great. Or is this feature already available?

Thanks!

thom4parisot commented 10 years ago

Good question.

If you use jQuery, you could benefit of the :visible selector like this:

new Imager($('.responsive-image:visible'))

Otherwise, apply a similar thing using plain JavaScript.

In any case, as far as I remember, even if the images are hidden on mobile, the browser will still load them. So Imager or not Imager, it will still be your problem and not an Imager's one.

Let me know what you think about it.

thom4parisot commented 10 years ago

@tdwesten hello, did you have time to test my solution?

thom4parisot commented 9 years ago

Checking if an image is visible is not part of the business of Imager.

If image resizing involves dynamic checking (updating only visible images on scroll/resize), then we could tinker some filter function.