<!DOCTYPE html>
<html>
<head> <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/croppie/2.6.2/croppie.js"></script>
<link rel="Stylesheet" href="https://cdn.bootcss.com/croppie/2.6.2/croppie.css" />
<style>
button,
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;
}
button:focus {
outline: 0;
} .file-btn {
position: relative;
}
.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;
}
.pop_main{display:none}
.pop_con{ width: 400px;
height: 400px;
background: #fff;
z-index: 100;
position: relative;}
.pop_mask{background-color: rgba(0, 0, 0, 0.5);position: absolute;
width: 100%;
left: 0;
top: 0;
bottom: 0;}
</style>
</head>
<body>
<div class="actions">
<button class="file-btn">
<span>上传</span>
<input type="file" id="upload" value="选择图片文件" />
</button> <div class="pop_main">
<div class="pop_con">
<div> <button class="pop_close">x</button> </div>
<div class="crop">
<div id="upload-demo"></div>
<button class="upload-result">裁剪</button>
</div> </div>
<div class="pop_mask"></div>
</div> <div id="result"></div>
</div>
<script>
$(function(){
var $uploadCrop; function readFile(input) {
if (input.files && input.files[0]) {
console.log("file----",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
}
}); $('#upload').on('change', function () {
$(".pop_main").show();
$(".pop_con").css({'top':0,'opacity':0})
$(".pop_con").animate({'top':'50%','opacity':1})
readFile(this);
});
$('.upload-result').on('click', function (ev) {
$uploadCrop.croppie('result', 'canvas').then(function (resp) {
console.log("file---2",resp)
popupResult({
src: resp
});
});
});
$('.pop_close').on('click',function(ev){
$(".pop_main").hide()
var file = $("#upload")
file.after(file.clone().val(""));
file.remove();
})
function popupResult(result) { var html;
if (result.html) {
html = result.html;
}
if (result.src) {
html = '<img src="' + result.src + '" />';
}
$("#result").html(html);
}
});
</script>
</body>
</html>

  

最新文章

  1. ElasticSearch5中文分词(IK)
  2. WEB前端开发人员须知的常见浏览器兼容问题及解决技巧
  3. 绘制图形与3D增强技巧(五)----多边形图元的使用及其他
  4. jquery满屏滚动代码
  5. java的字体的颜色,型号,大小的方法
  6. Spring知识点
  7. TP验证
  8. 用PHP操作http中Etag、lastModified和Expires标签
  9. boj1267 Infinite’s Cave 树形dp + 背包
  10. 编译lua5.3.2报错提示libreadline.so存在未定义的引用解决方法
  11. Deep Learning(深度学习)学习笔记整理系列之(一)
  12. ASP.NET Identity登录原理 - Claims-based认证和OWIN
  13. chapter 14_1 环境
  14. Spring简单的REST例子
  15. POJ2891 Strange Way to Express Integers [中国剩余定理]
  16. Python ymal 模块和configparser
  17. 3.18 总结 java 基础语法
  18. Azure CosmosDB (5) 高可用性
  19. 使用shell脚本监控用户登陆服务器并发送提示信息给微信
  20. 模拟实现memcpy 与 memmove

热门文章

  1. 关于tensor2tensor与tensorflow版本冲突的解决方案
  2. SAR成像(四):多普勒频移的计算
  3. Centos 升级glibc 亲测好用
  4. PHP日志组件Monolog的使用
  5. 超级详细的Vue安装与配置教程
  6. 如何使用命令行直接运行PHP脚本程序
  7. signalR从外部服务中推送消息和全局参数的设置
  8. (0821) git 下拉code不稳
  9. LocalDateTime与LocalDate
  10. Doris使用记录