forked from zhaomenghuan/mui-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
94 lines (90 loc) · 2.56 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<link href="css/mui.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/cropper.min.css" />
<link rel="stylesheet" href="css/mui.cropper.css"/ >
<style>
.avatar img{
width: 150px;
display: block;
margin: 20px auto;
cursor: pointer;
}
</style>
</head>
<body>
<header class="mui-bar mui-bar-nav">
<h1 class="mui-title">裁剪图像</h1>
</header>
<div class="mui-content">
<div class="avatar">
<a href="#cropper-sheet">
<img id="avatar" src="img/addHeadIcon.png"/>
</a>
</div>
<!--选择头像-->
<div id="cropper-sheet" class="mui-popover mui-popover-bottom mui-popover-action">
<!-- 可选择菜单 -->
<ul class="mui-table-view">
<li class="mui-table-view-cell">
<a data-type="camera">拍照</a>
</li>
<li class="mui-table-view-cell">
<a data-type="gallery">选择相册</a>
</li>
</ul>
<!-- 取消菜单 -->
<ul class="mui-table-view">
<li class="mui-table-view-cell">
<a href="#cropper-sheet"><b style="color: #ff0000;">取消</b></a>
</li>
</ul>
</div>
<div class="mui-cropper-modal mui-modal">
<div class="cropper-image-container">
<img id="image" src="" />
</div>
<div class="cropper-btn-group">
<span class="cropper-cancel">取消</span>
<span class="cropper-ok">裁剪</span>
</div>
</div>
</div>
<script src="js/mui.min.js"></script>
<script src="js/cropper.min.js"></script>
<script src="js/mui.cropper.js"></script>
<script type="text/javascript">
mui('#cropper-sheet').on('tap','.mui-table-view-cell > a',function(){
var type = this.getAttribute('data-type');
switch (type){
case 'camera':
mui.captureImage(function(path){
var fullPath = mui.getLocalFileURL(path);
handleInit(fullPath);
})
break;
case 'gallery':
mui.pickGallery(function(path){
handleInit(path);
})
break;
default:
break;
}
})
function handleInit(path){
mui('#cropper-sheet').popover('toggle');
mui.cropper.show(path, function(data){
mui.saveImage(data, '_doc/cropper.jpg', function(path){
console.log(path);
document.getElementById("avatar").src = path;
})
});
}
</script>
</body>
</html>