heimrichhannot/masonry-imagesloaded
最新稳定版本:4.1.1
Composer 安装命令:
composer require heimrichhannot/masonry-imagesloaded
包简介
JavaScript is all like _You images done yet or what?_
README 文档
README
Abandoned! See heimrichhannot-contao-components/imagesloaded instead!
JavaScript is all like "You images done yet or what?"
Detect when images have been loaded.
Install
Download
- imagesloaded.pkgd.min.js minified
- imagesloaded.pkgd.js un-minified
CDN
<script src="https://npmcdn.com/imagesloaded@4.1/imagesloaded.pkgd.min.js"></script> <!-- or --> <script src="https://npmcdn.com/imagesloaded@4.1/imagesloaded.pkgd.js"></script>
Package managers
Install via npm: npm install imagesloaded
Install via Bower: bower install imagesloaded --save
jQuery
You can use imagesLoaded as a jQuery Plugin.
$('#container').imagesLoaded( function() { // images have loaded }); // options $('#container').imagesLoaded( { // options... }, function() { // images have loaded } );
.imagesLoaded() returns a jQuery Deferred object. This allows you to use .always(), .done(), .fail() and .progress().
$('#container').imagesLoaded() .always( function( instance ) { console.log('all images loaded'); }) .done( function( instance ) { console.log('all images successfully loaded'); }) .fail( function() { console.log('all images loaded, at least one is broken'); }) .progress( function( instance, image ) { var result = image.isLoaded ? 'loaded' : 'broken'; console.log( 'image is ' + result + ' for ' + image.img.src ); });
Vanilla JavaScript
You can use imagesLoaded with vanilla JS.
imagesLoaded( elem, callback ) // options imagesLoaded( elem, options, callback ) // you can use `new` if you like new imagesLoaded( elem, callback )
elemElement, NodeList, Array, or Selector StringoptionsObjectcallbackFunction - function triggered after all images have been loaded
Using a callback function is the same as binding it to the always event (see below).
// element imagesLoaded( document.querySelector('#container'), function( instance ) { console.log('all images are loaded'); }); // selector string imagesLoaded( '#container', function() {...}); // multiple elements var posts = document.querySelectorAll('.post'); imagesLoaded( posts, function() {...});
Bind events with vanilla JS with .on(), .off(), and .once() methods.
var imgLoad = imagesLoaded( elem ); function onAlways( instance ) { console.log('all images are loaded'); } // bind with .on() imgLoad.on( 'always', onAlways ); // unbind with .off() imgLoad.off( 'always', onAlways );
Background
Detect when background images have loaded, in addition to <img>s.
Set { background: true } to detect when the element's background image has loaded.
// jQuery $('#container').imagesLoaded( { background: true }, function() { console.log('#container background image loaded'); }); // vanilla JS imagesLoaded( '#container', { background: true }, function() { console.log('#container background image loaded'); });
See jQuery demo or vanilla JS demo on CodePen.
Set to a selector string like { background: '.item' } to detect when the background images of child elements have loaded.
// jQuery $('#container').imagesLoaded( { background: '.item' }, function() { console.log('all .item background images loaded'); }); // vanilla JS imagesLoaded( '#container', { background: '.item' }, function() { console.log('all .item background images loaded'); });
See jQuery demo or vanilla JS demo on CodePen.
Events
always
// jQuery $('#container').imagesLoaded().always( function( instance ) { console.log('ALWAYS - all images have been loaded'); }); // vanilla JS imgLoad.on( 'always', function( instance ) { console.log('ALWAYS - all images have been loaded'); });
Triggered after all images have been either loaded or confirmed broken.
instanceimagesLoaded - the imagesLoaded instance
done
// jQuery $('#container').imagesLoaded().done( function( instance ) { console.log('DONE - all images have been successfully loaded'); }); // vanilla JS imgLoad.on( 'done', function( instance ) { console.log('DONE - all images have been successfully loaded'); });
Triggered after all images have successfully loaded without any broken images.
fail
$('#container').imagesLoaded().fail( function( instance ) { console.log('FAIL - all images loaded, at least one is broken'); }); // vanilla JS imgLoad.on( 'fail', function( instance ) { console.log('FAIL - all images loaded, at least one is broken'); });
Triggered after all images have been loaded with at least one broken image.
progress
imgLoad.on( 'progress', function( instance, image ) { var result = image.isLoaded ? 'loaded' : 'broken'; console.log( 'image is ' + result + ' for ' + image.img.src ); });
Triggered after each image has been loaded.
instanceimagesLoaded - the imagesLoaded instanceimageLoadingImage - the LoadingImage instance of the loaded image
Properties
LoadingImage.img
Image - The img element
LoadingImage.isLoaded
Boolean - true when the image has succesfully loaded
imagesLoaded.images
Array of LoadingImage instances for each image detected
var imgLoad = imagesLoaded('#container'); imgLoad.on( 'always', function() { console.log( imgLoad.images.length + ' images loaded' ); // detect which image is broken for ( var i = 0, len = imgLoad.images.length; i < len; i++ ) { var image = imgLoad.images[i]; var result = image.isLoaded ? 'loaded' : 'broken'; console.log( 'image is ' + result + ' for ' + image.img.src ); } });
Browserify
imagesLoaded works with Browserify.
npm install imagesloaded --save
var imagesLoaded = require('imagesloaded'); imagesLoaded( elem, function() {...} );
Use .makeJQueryPlugin to make to use .imagesLoaded() jQuery plugin.
var $ = require('jquery'); var imagesLoaded = require('imagesloaded'); // provide jQuery argument imagesLoaded.makeJQueryPlugin( $ ); // now use .imagesLoaded() jQuery plugin $('#container').imagesLoaded( function() {...});
Webpack
Install imagesLoaded with npm.
npm install imagesloaded
You can then require('imagesloaded').
// main.js var imagesLoaded = require('imagesloaded'); imagesLoaded( '#container', function() { // images have loaded });
Use .makeJQueryPlugin to make .imagesLoaded() jQuery plugin.
// main.js var imagesLoaded = require('imagesloaded'); var $ = require('jquery'); // provide jQuery argument imagesLoaded.makeJQueryPlugin( $ ); // now use .imagesLoaded() jQuery plugin $('#container').imagesLoaded( function() {...});
Run webpack.
webpack main.js bundle.js
RequireJS
imagesLoaded works with RequireJS.
You can require imagesloaded.pkgd.js.
requirejs( [ 'path/to/imagesloaded.pkgd.js', ], function( imagesLoaded ) { imagesLoaded( '#container', function() { ... }); });
Use .makeJQueryPlugin to make .imagesLoaded() jQuery plugin.
requirejs( [ 'jquery', 'path/to/imagesloaded.pkgd.js', ], function( $, imagesLoaded ) { // provide jQuery argument imagesLoaded.makeJQueryPlugin( $ ); // now use .imagesLoaded() jQuery plugin $('#container').imagesLoaded( function() {...}); });
You can manage dependencies with Bower. Set baseUrl to bower_components and set a path config for all your application code.
requirejs.config({ baseUrl: 'bower_components/', paths: { // path to your app app: '../' } }); requirejs( [ 'imagesloaded/imagesloaded', 'app/my-component.js' ], function( imagesLoaded, myComp ) { imagesLoaded( '#container', function() { ... }); });
Browser support
- IE9+
- Android 2.3+
- iOS Safari 4+
- All other modern browsers
Use imagesLoaded v3 for IE8 support.
MIT License
imagesLoaded is released under the MIT License. Have at it.
heimrichhannot/masonry-imagesloaded 适用场景与选型建议
heimrichhannot/masonry-imagesloaded 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 460 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ui」 「javascript」 「library」 「dom」 「images」 「jquery-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 heimrichhannot/masonry-imagesloaded 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 heimrichhannot/masonry-imagesloaded 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 heimrichhannot/masonry-imagesloaded 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
A library that provides basic utilities for creating HTML documents.
A bridge between SimpleXML and the DOM extension, plus a bunch of convenience methods
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
BigPipe: Pipelining web pages for high performance built in PHP.
统计信息
- 总下载量: 460
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-20