cropbox.js 介绍
cropbox.js是一款简单轻量级的头像图片剪裁插件。用户可以上传自己的图片,还可以将图片进行放大和缩小,以及对图片进行拖动,最后可以将图片剪裁生成新的头像图片。
cropbox.js支持纯js,或结合jquery来使用,或通过YUI来使用。
纯js调用插件
window.onload = function() {
var options =
{
imageBox: '.imageBox',
thumbBox: '.thumbBox',
spinner: '.spinner',
imgSrc: 'avatar.png'
}
var cropper = new cropbox(options);
document.querySelector('#file').addEventListener('change',function(){
var reader = new FileReader();
reader.onload = function(e) {
options.imgSrc = e.target.result;
cropper = new cropbox(options);
}
reader.readAsDataURL(this.files[0]);
this.files = [];
})
document.querySelector('#btnCrop').addEventListener('click',function(){
var img = cropper.getDataURL()
document.querySelector('.cropped').innerhtml += '<img src="'+img+'">';
})
document.querySelector('#btnZoomIn').addEventListener('click',function(){
cropper.zoomIn();
})
document.querySelector('#btnZoomOut').addEventListener('click',function(){
cropper.zoomOut();
})
};
jquery结合使用
$(window).load(function() {
var options =
{
thumbBox: '.thumbBox',
imgSrc: 'avatar.png'
}
var cropper = $('.imageBox').cropbox(options);
$('#file').on('change',function(){
var reader = new FileReader();
reader.onload = function(e) {
options.imgSrc = e.target.result;
cropper = $('.imageBox').cropbox(options);
}
reader.readAsDataURL(this.files[0]);
this.files = [];
})
$('#btnCrop').on('click',function(){
var img = cropper.getDataURL()
$('.cropped').append('<img src="'+img+'">');
})
$('#btnZoomIn').on('click',function(){
cropper.zoomIn();
})
$('#btnZoomOut').on('click',function(){
cropper.zoomOut();
})
});
// use with require js
paths: {
jquery: 'js/jquery-1.11.0.min',
cropbox: 'cropbox'
}
});
require( ["jquery","cropbox"],function($) {
var options =
{
thumbBox: '.thumbBox',function(){
var img = cropper.getDataURL();
$('.cropped').append('<img src="'+img+'">');
})
$('#btnZoomIn').on('click',function(){
cropper.zoomOut();
})
}
);
YUI插件使用
YUI().use('node','crop-box',function(Y){
var options =
{
imageBox: '.imageBox',
imgSrc: 'avatar.png'
}
var cropper = new Y.cropbox(options);
Y.one('#file').on('change',function(){
var reader = new FileReader();
reader.onload = function(e) {
options.imgSrc = e.target.result;
cropper = new Y.cropbox(options);
}
reader.readAsDataURL(this.get('files')._nodes[0]);
this.get('files')._nodes = [];
})
Y.one('#btnCrop').on('click',function(){
var img = cropper.getDataURL()
Y.one('.cropped').append('<img src="'+img+'">');
})
Y.one('#btnZoomIn').on('click',function(){
cropper.zoomIn();
})
Y.one('#btnZoomOut').on('click',function(){
cropper.zoomOut();
})
})
网站地址:http://hongkhanh.github.io/cropbox/
GitHub:https://github.com/hongkhanh/cropbox
网站描述:一款简单轻量级的头像图片剪裁插件
cropbox.js
官方网站:http://hongkhanh.github.io/cropbox/
小编说
以上是编程之家为你收集整理的cropbox.js全部内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。