-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a pendingSrc
or selectedSrc
property
#269
Comments
It'd be great to document these use cases, first here and eventually in the use cases document. |
I'm not so good in producing good use cases, but I would argue, that 90% off all use cases for the current Here is an example using Although not really a good use case, it also shows that the working of Here is another not so good use case: https://github.com/aFarkas/lazysizes/tree/gh-pages/plugins/bgset This means, the script does not support progressive image loading, because I have to wait until the image is fully loaded. Although this isn't such a great use case either, it shows that in most cases you want to get the |
Do you want to be notified when a new candidate is selected? If so, maybe an event is better than a property. This is why we need use cases. :-) |
An additional event would make this awesome (in case the Do you have any use cases for I think I saw a code example (by yoav), showing this: //get currentSrc for modern and legacy browsers
var curSrc = img.currentSrc || img.src; In fact this isn't true. The semantics are slightly different. And you need to write something like this to get some reliable results: var getSrc = function(img, cb){
var call = function(){
img.removeEventListener('load', call);
img.removeEventListener('error', call);
cb(img.currentSrc || img.src);
};
img.addEventListener('load', call);
img.addEventListener('error', call);
if(img.complete){
call();
}
}; As I first worked with So I think This issue is caused by the fact, that I can't detect, what candidate the browser has chosen, before this candidate is fully available. |
Just to end this. In case we would have var curSrc = img.pendingSrc || img.currentSrc || img.src; And in case we have var curSrc = img.selectedSrc || img.src; |
+1. The use cases would be polyfills and highly customized layout behaviors. For example the author needs to do custom positioning for an overlay over an art-directed image.. The term |
Currently there is the
currentSrc
property to get the URL of the current request.In most use cases where there is also a pending request, the
currentSrc
isn't that interesting anymore, because it will change soon. It would be great to also have an API to get either the URL of the pending request (i.e.:pendingSrc
) or a property that returns either the pending request if it is not null or the current request if the pending request is null (i.e:selectedSrc
).The text was updated successfully, but these errors were encountered: