{"id":13825608,"url":"https://github.com/lukeed/onloaded","last_synced_at":"2025-10-09T18:24:01.838Z","repository":{"id":57314785,"uuid":"98915379","full_name":"lukeed/onloaded","owner":"lukeed","description":"A tiny (350B) library to detect when images have loaded.","archived":false,"fork":false,"pushed_at":"2019-12-03T19:54:55.000Z","size":7,"stargazers_count":39,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-25T05:45:09.335Z","etag":null,"topics":["images","imagesloaded","is-loading","javascript","lightweight","ready"],"latest_commit_sha":null,"homepage":"https://jsfiddle.net/lukeed/8njejbjz/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-31T18:02:50.000Z","updated_at":"2023-12-10T03:14:38.000Z","dependencies_parsed_at":"2022-09-12T15:02:00.915Z","dependency_job_id":null,"html_url":"https://github.com/lukeed/onloaded","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lukeed/onloaded","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fonloaded","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fonloaded/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fonloaded/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fonloaded/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/onloaded/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fonloaded/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263402488,"owners_count":23461186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["images","imagesloaded","is-loading","javascript","lightweight","ready"],"created_at":"2024-08-04T09:01:24.159Z","updated_at":"2025-10-09T18:23:56.788Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# onloaded\n\n\u003e A tiny (350B) library to detect when images have loaded\n\n[Demo](https://jsfiddle.net/lukeed/8njejbjz/)\n\nThis module exposes three module definitions:\n\n* **ES Module**: `dist/onloaded.es.js`\n* **CommonJS**: `dist/onloaded.js`\n* **UMD**: `dist/onloaded.min.js`\n\nIf using the UMD bundle, the library is exposed as `onloaded` globally.\n\n\n## Install\n\n```\n$ npm install --save onloaded\n```\n\n\n## Usage\n\n```js\nconst onloaded = require('onloaded');\n\n// passing a selector to `elem`\nonloaded('#container \u003e img', {\n  onLoad(img) {\n    img.className += ' loaded';\n  },\n  onError(img) {\n    img.className += ' failed';\n  },\n  onProgress(val) {\n    console.log(`I am ${ val * 100 }% complete!`);\n  },\n  onComplete(val, stats) {\n    // val is always 1 ~~\u003e 100%\n    console.log('This callback always runs!');\n    console.log(`  ${stats.loaded} loaded`);\n    console.log(`  ${stats.failed} failed`);\n    console.log(`  ${stats.total} total`);\n  }\n});\n```\n\n\u003e **Note:** Visit [`elem`](#elem) for other possibilities!\n\n\n## API\n\n### onloaded(elem, options)\n\n#### elem\n\nType: `String|Node|NodeList`\n\nYou have several options here:\n\n1. Pass a selector string to `img` element(s);\n    ```js\n    onloaded('.container img', { ... });\n    ```\n\n2. Pass a reference to a specific `\u003cimg /\u003e` DOM Node;\n    ```js\n    var img = document.querySelector('.container img');\n    onloaded(img, { ... });\n    ```\n\n3. Pass a reference to a multiple `\u003cimg /\u003e` DOM Nodes;\n    ```js\n    var imgs = document.querySelectorAll('.container img');\n    onloaded(imgs, { ... });\n    ```\n\n4. Pass a reference to a container DOM Node that contains `\u003cimg /\u003e` elements;\n    ```js\n    var parent = document.querySelector('.container');\n    onloaded(parent, { ... });\n    ```\n\n#### options.onError(node)\n\nType: `Function`\n\nCallback whenever an image source failed to load. Receives the `\u003cimg /\u003e` DOM node;\n\n#### options.onLoad(node)\n\nType: `Function`\n\nCallback whenever an image source sucessfully loads. Receives the `\u003cimg /\u003e` DOM node;\n\n#### options.onProgress(val, stats)\n\nType: `Function`\n\nCallback whenever an image's network request has completed, regardless of success or failure.\n\nReceives the current \"progress\" of completed requests as a decimal.\n\nAlso receives a `stats` object with `loaded`, `failed`, and `total` keys.\n\n#### options.onComplete(val, stats)\n\nType: `Function`\n\nCallback when _all_ network requests have completed, regardless of success or failure.\n\nReceives the \"progress\" as its first parameter. This will always equal `1`.\n\nAlso receives a `stats` object with `loaded`, `failed`, and `total` keys.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fonloaded","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fonloaded","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fonloaded/lists"}