Giter Club home page Giter Club logo

imguploader's Introduction

imgUploader.js

HTML5多图片上传插件

特性

  • 不依赖任何js库
  • 支持多图片上传
  • 支持图片压缩(根据上传图片的大小合理选择压缩质量)
  • 提供文件读取的精确流程控制接口

使用方法

使用读取文件流程控制函数

<form id="imgFile" name="imgFile">
    <input name="image" type="file" multiple id="upload" class="upload-input" />
</form>

<script type="text/javascript">
	document.getElementById('upload').addEventListener('change',function(){
        var uploader = new imgUploader(this.files);
        /* 开始读取文件 */
        uploader.on('start',function(){
            //你的代码
        });
        /* 每读取完一张图片 */
        uploader.on('progress',function(img){
            //img为当前读取到的图片,是一个img标签
        });
        /* 文件读取结束 */
        uploader.on('finish',function(){
            //uploader.getDataUrl() 该方法可以获取压缩后的图片base64字符串列表
            var dataUrlList = uploader.getDataUrl();
        });
    },false);
</script>

使用upload(cb)回调函数

<form id="imgFile" name="imgFile">
    <input name="image" type="file" multiple id="upload" class="upload-input" />
</form>

<script type="text/javascript">
	document.getElementById('upload').addEventListener('change',function(){
		var uploader = new imgUploader(this.files);
		uploader.upload(function(){
		    //uploader.getDataUrl() 该方法可以获取压缩后的图片base64字符串列表
		    var dataUrlList = uploader.getDataUrl();
		});
	});
</script>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.