-
Notifications
You must be signed in to change notification settings - Fork 158
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
Onload attribute method #70
Comments
The onload attribute does the trick of adding the image to the list of image to lazyload by using the browser onload attribute on an empty/small image. Otherwise we would have to rely on document dom ready and it's not faster enough because you have to wait for all scripts/css to load. One possibility was to add a global onload dynamically on the body and then see if the event would bubble up (using useCapture), and filter based on the dom node. Could be a very good possibility, reference: https://twitter.com/zeroload/status/386861545256280065 |
=== Welcoming any improvement if it does make a difference/simplify the integration. Adding onload with useCapture on body element is interesting, but you first need to have a reference to the body element anywhere (even when included in the ) |
also see #45 |
It's already possible to write something like this : lzld(document.querySelector('.element')); That means you can trigger the lazyload detection whenever you want, with the syntax you think is right. With a small modification of the library that I made, one can even support arrays of DOM nodes : function register(elt) {
// flatten the execution of the register function
if('length' in elt){
for (var i = 0; i < elt.length; i++) {
register(elt[i]);
}
return;
} |
@jpvincent would be a great addition to the library. Also yes you can trigger manually, it may be slower than onload= but can make sense in SPA where you control everything |
sure, will think about it |
cc @jpvincent |
I do it without onload attr in HTML mark-up:
|
Nice! Thanks for the feedback. |
Sorry to revive an old issue, but I was searching how to do exactly what @englishextra had accomplished, but wouldn't this script be a little more performant and simpler?
|
@AndrewCraswell This is what I use now. It appears that the fastest would be to set up a technical CSS class, and then select with I try to avoid
You will need that class, for instance, to set up CSS transition opacity. |
Hello,
I'm just wondering if there is a version of the script without setting up
onload="lzld(this)"
in the HTML code ?As I'm using CSP and trying to avoid inline js-attributes, would it be possible to set up a version with an data-attribute (for example) instead of onload ?
Thanks a lot for reading,
Nicolas
The text was updated successfully, but these errors were encountered: