-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
52 lines (52 loc) · 1.63 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>移动端图片上传裁切demo</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
</head>
<body>
<div>
<div class="upload-wrap">
<img id="previewResult"/>
<button class="file-input-mask"><input type="file" id="file" accept="image/*" /></button>
</div>
<img id="preview"/>
</div>
</body>
<script type="text/javascript" src="js/JQuery-3.1.1.min.js"></script>
<script src="js/resize.min.js"></script>
<script src="js/alloy_crop.js"></script>
<script src="js/transform.js"></script>
<script src="js/alloy_finger.js"></script>
<script type="text/javascript">
(function () {
var _input = document.querySelector('#file')
_input.addEventListener('change', function (e) {
canvasResize(this.files[0], {
crop: false,
quality: 0.9,
rotate: 0,
callback(baseStr) {
$("#preview").attr("src",baseStr).hide();
var crop_btn = document.querySelector("#crop_btn");
new AlloyCrop({
image_src: $("#preview").attr("src"),
width: 300,
height: 300,
ok_text: "确定", // optional parameters , the default value is ok
cancel_text: "取消", // optional parameters , the default value is cancel
ok: function (base64, canvas) {
$("#previewResult").attr('src',base64);
$(".file-input-mask").css("opacity","0");
},
cancel: function () {
// 取消回调
}
})
}
})
})
})()
</script>
</html>