ie js html 压缩,H5图片裁剪-压缩-上传-神奇的Croppie.js

Croppie.js之图片裁剪压缩上传

h5图片裁剪, 压缩, 上传, 预览是常见功能, 幸运的是我们有cropp.js这款利器.

1. style

.actions button,

.actions a.btn {

background-color: #189094;

color: white;

padding: 10px 15px;

border-radius: 3px;

border: 1px solid rgba(255, 255, 255, 0.5);

font-size: 16px;

cursor: pointer;

text-decoration: none;

text-shadow: none;

}

.actions button:focus {

outline: 0;

}

.actions .file-btn {

position: relative;

}

.actions .file-btn input[type="file"] {

position: absolute;

top: 0;

left: 0;

width: 100%;

height: 100%;

opacity: 0;

}

.actions {

padding: 5px 0;

}

.actions button {

margin-right: 5px;

}

.actions .crop{display:none}

2.html

上传

裁剪

3.JavaScript

$(function(){

var $uploadCrop;

function readFile(input) {

if (input.files && input.files[0]) {

var reader = new FileReader();

reader.onload = function (e) {

$uploadCrop.croppie('bind', {

url: e.target.result

});

}

reader.readAsDataURL(input.files[0]);

}

else {

alert("Sorry - you're browser doesn't support the FileReader API");

}

}

$uploadCrop = $('#upload-demo').croppie({

viewport: {

width: 200,

height: 200,

type: 'circle'

},

boundary: {

width: 300,

height: 300

},

showZoomer: false,

});

$('#upload').on('change', function () {

$(".crop").show();

readFile(this);

});

$('.upload-result').on('click', function (ev) {

$uploadCrop.croppie('result', 'canvas').then(function (resp) {

popupResult({

src: resp

});

});

});

function popupResult(result) {

var html;

if (result.html) {

html = result.html;

}

if (result.src) {

html = ''%20+%20result.src%20+%20'';

}

$("#result").html(html);

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值