{"id":13404214,"url":"https://github.com/desandro/imagesloaded","last_synced_at":"2025-05-14T22:05:36.347Z","repository":{"id":44437196,"uuid":"2269353","full_name":"desandro/imagesloaded","owner":"desandro","description":":camera: JavaScript is all like \"You images done yet or what?\"","archived":false,"fork":false,"pushed_at":"2022-02-22T00:04:14.000Z","size":573,"stargazers_count":8893,"open_issues_count":15,"forks_count":1143,"subscribers_count":227,"default_branch":"master","last_synced_at":"2025-05-14T22:04:16.260Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://imagesloaded.desandro.com","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/desandro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-08-25T17:28:58.000Z","updated_at":"2025-05-11T01:09:25.000Z","dependencies_parsed_at":"2022-09-09T10:51:43.416Z","dependency_job_id":null,"html_url":"https://github.com/desandro/imagesloaded","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/desandro%2Fimagesloaded","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/desandro%2Fimagesloaded/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/desandro%2Fimagesloaded/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/desandro%2Fimagesloaded/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/desandro","download_url":"https://codeload.github.com/desandro/imagesloaded/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235687,"owners_count":22036962,"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":[],"created_at":"2024-07-30T19:01:40.832Z","updated_at":"2025-05-14T22:05:36.309Z","avatar_url":"https://github.com/desandro.png","language":"JavaScript","readme":"# imagesLoaded\n\n\u003cp class=\"tagline\"\u003eJavaScript is all like \"You images done yet or what?\"\u003c/p\u003e\n\n[imagesloaded.desandro.com](https://imagesloaded.desandro.com)\n\nDetect when images have been loaded.\n\n## Install\n\n### Download\n\n+ [imagesloaded.pkgd.min.js](https://unpkg.com/imagesloaded@5/imagesloaded.pkgd.min.js) minified\n+ [imagesloaded.pkgd.js](https://unpkg.com/imagesloaded@5/imagesloaded.pkgd.js) un-minified\n\n### CDN\n\n``` html\n\u003cscript src=\"https://unpkg.com/imagesloaded@5/imagesloaded.pkgd.min.js\"\u003e\u003c/script\u003e\n\u003c!-- or --\u003e\n\u003cscript src=\"https://unpkg.com/imagesloaded@5/imagesloaded.pkgd.js\"\u003e\u003c/script\u003e\n```\n\n### Package managers\n\nInstall via npm: `npm install imagesloaded`\n\nInstall via Yarn: `yarn add imagesloaded`\n\n## jQuery\n\nYou can use imagesLoaded as a jQuery Plugin.\n\n``` js\n$('#container').imagesLoaded( function() {\n  // images have loaded\n});\n\n// options\n$('#container').imagesLoaded( {\n  // options...\n  },\n  function() {\n    // images have loaded\n  }\n);\n```\n\n`.imagesLoaded()` returns a [jQuery Deferred object](https://api.jquery.com/category/deferred-object/). This allows you to use `.always()`, `.done()`, `.fail()` and `.progress()`.\n\n``` js\n$('#container').imagesLoaded()\n  .always( function( instance ) {\n    console.log('all images loaded');\n  })\n  .done( function( instance ) {\n    console.log('all images successfully loaded');\n  })\n  .fail( function() {\n    console.log('all images loaded, at least one is broken');\n  })\n  .progress( function( instance, image ) {\n    var result = image.isLoaded ? 'loaded' : 'broken';\n    console.log( 'image is ' + result + ' for ' + image.img.src );\n  });\n```\n\n## Vanilla JavaScript\n\nYou can use imagesLoaded with vanilla JS.\n\n``` js\nimagesLoaded( elem, callback )\n// options\nimagesLoaded( elem, options, callback )\n// you can use `new` if you like\nnew imagesLoaded( elem, callback )\n```\n\n+ `elem` _Element, NodeList, Array, or Selector String_\n+ `options` _Object_\n+ `callback` _Function_ - function triggered after all images have been loaded\n\nUsing a callback function is the same as binding it to the `always` event (see below).\n\n``` js\n// element\nimagesLoaded( document.querySelector('#container'), function( instance ) {\n  console.log('all images are loaded');\n});\n// selector string\nimagesLoaded( '#container', function() {...});\n// multiple elements\nvar posts = document.querySelectorAll('.post');\nimagesLoaded( posts, function() {...});\n```\n\nBind events with vanilla JS with .on(), .off(), and .once() methods.\n\n``` js\nvar imgLoad = imagesLoaded( elem );\nfunction onAlways( instance ) {\n  console.log('all images are loaded');\n}\n// bind with .on()\nimgLoad.on( 'always', onAlways );\n// unbind with .off()\nimgLoad.off( 'always', onAlways );\n```\n\n## Background\n\nDetect when background images have loaded, in addition to `\u003cimg\u003e`s.\n\nSet `{ background: true }` to detect when the element's background image has loaded.\n\n``` js\n// jQuery\n$('#container').imagesLoaded( { background: true }, function() {\n  console.log('#container background image loaded');\n});\n\n// vanilla JS\nimagesLoaded( '#container', { background: true }, function() {\n  console.log('#container background image loaded');\n});\n```\n\n[See jQuery demo](https://codepen.io/desandro/pen/pjVMPB) or [vanilla JS demo](https://codepen.io/desandro/pen/avKooW) on CodePen.\n\nSet to a selector string like `{ background: '.item' }` to detect when the background images of child elements have loaded.\n\n``` js\n// jQuery\n$('#container').imagesLoaded( { background: '.item' }, function() {\n  console.log('all .item background images loaded');\n});\n\n// vanilla JS\nimagesLoaded( '#container', { background: '.item' }, function() {\n  console.log('all .item background images loaded');\n});\n```\n\n[See jQuery demo](https://codepen.io/desandro/pen/avKoZL) or [vanilla JS demo](https://codepen.io/desandro/pen/vNrBGz) on CodePen.\n\n## Events\n\n### always\n\n``` js\n// jQuery\n$('#container').imagesLoaded().always( function( instance ) {\n  console.log('ALWAYS - all images have been loaded');\n});\n\n// vanilla JS\nimgLoad.on( 'always', function( instance ) {\n  console.log('ALWAYS - all images have been loaded');\n});\n```\n\nTriggered after all images have been either loaded or confirmed broken.\n\n+ `instance` _imagesLoaded_ - the imagesLoaded instance\n\n### done\n\n``` js\n// jQuery\n$('#container').imagesLoaded().done( function( instance ) {\n  console.log('DONE  - all images have been successfully loaded');\n});\n\n// vanilla JS\nimgLoad.on( 'done', function( instance ) {\n  console.log('DONE  - all images have been successfully loaded');\n});\n```\n\nTriggered after all images have successfully loaded without any broken images.\n\n### fail\n\n``` js\n$('#container').imagesLoaded().fail( function( instance ) {\n  console.log('FAIL - all images loaded, at least one is broken');\n});\n\n// vanilla JS\nimgLoad.on( 'fail', function( instance ) {\n  console.log('FAIL - all images loaded, at least one is broken');\n});\n```\n\nTriggered after all images have been loaded with at least one broken image.\n\n### progress\n\n``` js\nimgLoad.on( 'progress', function( instance, image ) {\n  var result = image.isLoaded ? 'loaded' : 'broken';\n  console.log( 'image is ' + result + ' for ' + image.img.src );\n});\n```\n\nTriggered after each image has been loaded.\n\n+ `instance` _imagesLoaded_ - the imagesLoaded instance\n+ `image` _LoadingImage_ - the LoadingImage instance of the loaded image\n\n\u003c!-- sponsored --\u003e\n\n## Properties\n\n### LoadingImage.img\n\n_Image_ - The `img` element\n\n### LoadingImage.isLoaded\n\n_Boolean_ - `true` when the image has successfully loaded\n\n### imagesLoaded.images\n\nArray of _LoadingImage_ instances for each image detected\n\n``` js\nvar imgLoad = imagesLoaded('#container');\nimgLoad.on( 'always', function() {\n  console.log( imgLoad.images.length + ' images loaded' );\n  // detect which image is broken\n  for ( var i = 0, len = imgLoad.images.length; i \u003c len; i++ ) {\n    var image = imgLoad.images[i];\n    var result = image.isLoaded ? 'loaded' : 'broken';\n    console.log( 'image is ' + result + ' for ' + image.img.src );\n  }\n});\n```\n\n## Webpack\n\nInstall imagesLoaded with npm.\n\n``` bash\nnpm install imagesloaded\n```\n\nYou can then `require('imagesloaded')`.\n\n``` js\n// main.js\nvar imagesLoaded = require('imagesloaded');\n\nimagesLoaded( '#container', function() {\n  // images have loaded\n});\n```\n\nUse `.makeJQueryPlugin` to make `.imagesLoaded()` jQuery plugin.\n\n``` js\n// main.js\nvar imagesLoaded = require('imagesloaded');\nvar $ = require('jquery');\n\n// provide jQuery argument\nimagesLoaded.makeJQueryPlugin( $ );\n// now use .imagesLoaded() jQuery plugin\n$('#container').imagesLoaded( function() {...});\n```\n\nRun webpack.\n\n``` bash\nwebpack main.js bundle.js\n```\n\n## Browserify\n\nimagesLoaded works with [Browserify](https://browserify.org/).\n\n``` bash\nnpm install imagesloaded --save\n```\n\n``` js\nvar imagesLoaded = require('imagesloaded');\n\nimagesLoaded( elem, function() {...} );\n```\n\nUse `.makeJQueryPlugin` to make to use `.imagesLoaded()` jQuery plugin.\n\n``` js\nvar $ = require('jquery');\nvar imagesLoaded = require('imagesloaded');\n\n// provide jQuery argument\nimagesLoaded.makeJQueryPlugin( $ );\n// now use .imagesLoaded() jQuery plugin\n$('#container').imagesLoaded( function() {...});\n```\n\n\n## Browser support\n\n+ Chrome 49+\n+ Firefox 41+\n+ Edge 14+\n+ iOS Safari 8+\n\nUse [imagesLoaded v4](https://github.com/desandro/imagesloaded/tree/v4.1.4) for Internet Explorer and other older browser support.\n\n## Development\n\nDevelopment uses Node.js v16 with npm v8\n\n``` bash\nnvm use\n```\n\n## MIT License\n\nimagesLoaded is released under the [MIT License](https://desandro.mit-license.org/). Have at it.\n","funding_links":[],"categories":["JavaScript","HarmonyOS","目录","13. 页面交互","jQuery Components"],"sub_categories":["Windows Manager","13.3 懒加载/加载监听/预加载 ###","13.3 懒加载/加载监听/预加载"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdesandro%2Fimagesloaded","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdesandro%2Fimagesloaded","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdesandro%2Fimagesloaded/lists"}