forked from Beau-zihan/WebIM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavatar.html
More file actions
67 lines (65 loc) · 3.05 KB
/
avatar.html
File metadata and controls
67 lines (65 loc) · 3.05 KB
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
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/avatar.css" media="all">
<style type="text/css">
body{background: #fafafa;}
button{clear: both;display: block;padding:5px 15px;}
</style>
</head>
<body>
<div class="avatarbox">
<div class="imgproview_b">
<div class="imgcenter">
<input style="display: none" type="file" name="" id="uploadpic">
</div>
</div>
<div class="imgproview">
<div class="imgbox_b"><div></div><span>中尺寸头像50×50像素</span></div>
<div class="imgbox_s"><div></div><span>小尺寸头像30×30像素</span></div>
</div>
<button>保存头像</button>
</div>
<script type="text/javascript" src="js/jQuery-1.7.1.min.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript" src="js/jquery.Jcrop.js"></script>
<script type="text/javascript">
$(function($){
$("#uploadpic").uploadify({
auto:true,
height: 36,
swf: 'uploadify/uploadify.swf',
uploader: 'avatar.html',
width: 101,
buttonText:"",
onUploadStart:function(file){
$(".imgcenter").html("").addClass("uploading");
},
onUploadSuccess:function(file, data, response){
userAvatar(data);//返回的data值为图片的地址
},
onUploadError:function(data){
}
});
function userAvatar(picUrl){
$(".imgcenter").html("<img src="+picUrl+" id='target' alt='Flowers' />").addClass("uploadcomplete");
$(".imgbox_b div").append("<img src="+picUrl+" id='preview_b' alt='Preview' class='jcrop-preview' />");
$(".imgbox_s div").append("<img src="+picUrl+" id='preview_s' alt='Preview' class='jcrop-preview' />");
$(".imgproview").append('<div class="imgbox_s"><a href="javacript:;">重新上传</a></div>');
var jcrop_api, boundx, boundy;
$('#target').Jcrop({onChange: updatePreview,onSelect: updatePreview,bgOpacity: .8,aspectRatio: 1},function(){
var bounds = this.getBounds();boundx = bounds[0];boundy = bounds[1];jcrop_api = this;});
function updatePreview(c){
if (parseInt(c.w) > 0){
var rxb = 50 / c.w,ryb = 50 / c.h,rxs = 30 / c.w,rys = 30 / c.h;
$('#preview_b').css({width: Math.round(rxb * boundx) + 'px',height: Math.round(ryb * boundy) + 'px',marginLeft: '-' + Math.round(rxb * c.x) + 'px', marginTop: '-' + Math.round(ryb * c.y) + 'px'});
$('#preview_s').css({width: Math.round(rxs * boundx) + 'px',height: Math.round(rys * boundy) + 'px',marginLeft: '-' + Math.round(rxs * c.x) + 'px',marginTop: '-' + Math.round(rys * c.y) + 'px'});
}
};
}
});
</script>
</body>
</html>