Coder Social home page Coder Social logo

cryst4lmao / tinyimgupload Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gitwd/tinyimgupload

0.0 2.0 0.0 5 KB

A flexible and independent image upload plugin that can preview and upload image asynchronously

License: MIT License

CSS 15.32% HTML 11.87% JavaScript 72.81%

tinyimgupload's Introduction

tinyImgUpload

一个灵活的图片上传插件,支持预览和异步上传图片,并且不依赖jQuery等js库。
A flexible and independent image upload plugin that can preview and upload image asynchronously.

使用方法

执行tinyImgUpload方法   tinyImgUpload(ele, options)
@param ele [string] [生成组件的元素的选择器]
@param options [Object] [对组件设置的基本参数]
options具体参数如下

  • path 图片上传的地址路径 必需
  • onSuccess(res) 文件上传成功后的回调 参数为返回的文本 必需
  • onFailure(res) 文件上传失败后的回调 参数为返回的文本 必需

@return [function] [执行图片上传的函数]

示例
用户引入插件代码后,只需要像下面这样,设置一些参数,然后执行一个方法就生成一个图片上传组件。

<div id="upload"></div>  // 这是用来生成图片上传组件的div
<script>
// 设置参数
var options = {
    path: '/',    // 上传图片时指定的地址路径,类似form变淡的action属性
    onSuccess: function (res) {    // 上传成功后执行的方法,res是接收的ajax响应内容
        console.log(res);  
    },
    onFailure: function (res) {    // 上传失败后执行的方法,res是接收的ajax响应内容
        console.log(res);
    }
}
// 执行生成图片上传插件的方法, 第一个参数是上面提到的准备生成组件的div选择器,第二个参数是设置的组件信息,执行方法后返回一个函数指针,指向执行上传功能的函数,通过把执行上传功能的函数暴露出来,用户就可以自己控制何时上传图片了。
var upload = tinyImgUpload('#upload', options);  
</script>

tinyimgupload's People

Contributors

gitwd avatar

Watchers

 avatar  avatar

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.