bbc / Imager.js

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

[PROPOSAL] Delaying width calculation and `src` replacement #26

Closed thom4parisot closed 10 years ago

thom4parisot commented 10 years ago

The intention

Imager replaces the images either on the next Animation Frame or in the next supposed to be frame interval (16.6ms + 4ms w/ setTimeout).

We might not want to replace any src of a same pool at the same pace:

My concern is Imager should not do too many things outside of its scope (resizing images when asked).

The proposal

This is especially relevant and less head-painful if events are not bundled anymore (cf. #25).

In any case, it will use setTimeout as a fallback if requestAnimationFrame is not available. It will wait the correct amount of Animation Frames

update(optional_delay)

Immediate:

imgr.update();

In 500ms:

imgr.update(500);

When I want:

$(window).on('resize', function(){
  imgr.update(250);
});

$(window).on('load news.updated', function(){
  imgr.update();
});

$(document).bind('scrollstop', function() {
  imgr.update();
});

delay configuration option

var imgr = new Imager({
  delay: 50     //50 ms or 1 frame
});

Wondering what update() without any arguments would mean now or with config delay.

Integralist commented 10 years ago

@oncletom again, I really like this proposal.

If I understood your last question correctly...

Wondering what update() without any arguments would mean now or with config delay

...then I would assume that if no delay configuration property was set when instantiating Imager then imgr.update(); should mean immediately.

But if a config property was set (for example delay: 50) then imgr.update(); should mean "update in 50 milliseconds" (or however long in milliseconds the user specified)

thom4parisot commented 10 years ago

Ok that makes sense :-)

And you understood well (hey, it looks like I start to be almost understandable codely-speaking ;-))

Integralist commented 10 years ago

Getting there :-)

Integralist commented 10 years ago

@oncletom just to confirm that I think this proposal seems fine to me.