Commit 14e2763d8d5559c3390ebd0970b6ef1bbf641a16
1 parent
cf9d491b
[年会抽奖]调试头像尺寸
Showing
2 changed files
with
74 additions
and
44 deletions
mobile.html
@@ -63,7 +63,7 @@ | @@ -63,7 +63,7 @@ | ||
63 | .pic-img-wrap {position: relative;width: 4.78rem;height: 4.78rem;margin: .5rem auto 0;box-sizing: border-box;padding: .96rem .92rem .98rem 1.02rem;} | 63 | .pic-img-wrap {position: relative;width: 4.78rem;height: 4.78rem;margin: .5rem auto 0;box-sizing: border-box;padding: .96rem .92rem .98rem 1.02rem;} |
64 | .pic-img-bg {position: absolute;top: 0;left: 0;z-index: 1;width: 100%;height: 100%;background: url('./img/mobile/pic_avatar_bg.png') no-repeat;background-size: 100% 100%;} | 64 | .pic-img-bg {position: absolute;top: 0;left: 0;z-index: 1;width: 100%;height: 100%;background: url('./img/mobile/pic_avatar_bg.png') no-repeat;background-size: 100% 100%;} |
65 | .pic-avatar-wrap {width: 2.84rem;height: 2.84rem;border-radius: 50%;overflow: hidden;} | 65 | .pic-avatar-wrap {width: 2.84rem;height: 2.84rem;border-radius: 50%;overflow: hidden;} |
66 | - .pic-avatar {} | 66 | + .pic-avatar {width: 2.84rem;} |
67 | .pic-btn-wrap {position: absolute;bottom: 1.2rem;left: 50%;transform: translateX(-50%);width: 6.82rem;padding-bottom: .72rem;} | 67 | .pic-btn-wrap {position: absolute;bottom: 1.2rem;left: 50%;transform: translateX(-50%);width: 6.82rem;padding-bottom: .72rem;} |
68 | .pic-btn-album {position: absolute;bottom: 0;left: 50%;transform: translateX(-50%);width: 3rem;display: flex;align-items: center;justify-content: center;} | 68 | .pic-btn-album {position: absolute;bottom: 0;left: 50%;transform: translateX(-50%);width: 3rem;display: flex;align-items: center;justify-content: center;} |
69 | .pic-btn-album .album-text {font-size: .28rem;color: #fff;margin-right: .1rem;} | 69 | .pic-btn-album .album-text {font-size: .28rem;color: #fff;margin-right: .1rem;} |
@@ -76,7 +76,7 @@ | @@ -76,7 +76,7 @@ | ||
76 | .info-center {position: absolute;top: .4rem;left: 50%;transform: translateX(-50%);} | 76 | .info-center {position: absolute;top: .4rem;left: 50%;transform: translateX(-50%);} |
77 | .user-avatar {position: relative;width: 1.34rem;height: 1.4rem;box-sizing: border-box;padding-top: .24rem;padding-left: .18rem;margin: 0 auto;overflow: hidden;} | 77 | .user-avatar {position: relative;width: 1.34rem;height: 1.4rem;box-sizing: border-box;padding-top: .24rem;padding-left: .18rem;margin: 0 auto;overflow: hidden;} |
78 | .user-avatar .avatar-img-wrap {width: 1.14rem;height: 1.14rem;border-radius: 50%;overflow: hidden;} | 78 | .user-avatar .avatar-img-wrap {width: 1.14rem;height: 1.14rem;border-radius: 50%;overflow: hidden;} |
79 | - .user-avatar .avatar-img {} | 79 | + .user-avatar .avatar-img {width: 1.14rem;} |
80 | .user-avatar .avatar-border {position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: url('./img/mobile/home_avatar.png') no-repeat;background-size: 100% 100%;} | 80 | .user-avatar .avatar-border {position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: url('./img/mobile/home_avatar.png') no-repeat;background-size: 100% 100%;} |
81 | .info-center .user-name {text-align: center;font-size: .36rem;font-weight: 500;color: #C93120;margin-top: .1rem;} | 81 | .info-center .user-name {text-align: center;font-size: .36rem;font-weight: 500;color: #C93120;margin-top: .1rem;} |
82 | .info-main {position: absolute;bottom: .8rem;left: 50%;transform: translateX(-50%); width: 6.3rem; height: .82rem;display: flex;align-items: center;} | 82 | .info-main {position: absolute;bottom: .8rem;left: 50%;transform: translateX(-50%); width: 6.3rem; height: .82rem;display: flex;align-items: center;} |
mobile.js
@@ -107,7 +107,7 @@ var action = { | @@ -107,7 +107,7 @@ var action = { | ||
107 | if (action.userInfo) { | 107 | if (action.userInfo) { |
108 | var userAvatar = action.userAvatar || defaultAvatar; | 108 | var userAvatar = action.userAvatar || defaultAvatar; |
109 | $('#home_user_avatar').attr('src', userAvatar); | 109 | $('#home_user_avatar').attr('src', userAvatar); |
110 | - action.loadImage('.user-avatar .avatar-img', '.user-avatar .avatar-img-wrap'); | 110 | + action.loadImage(userAvatar, '.user-avatar .avatar-img', '.user-avatar .avatar-img-wrap'); |
111 | $('#home_user_name').html(action.userInfo.realname); | 111 | $('#home_user_name').html(action.userInfo.realname); |
112 | $('#home_prize_no').html(action.userInfo.prize_no); | 112 | $('#home_prize_no').html(action.userInfo.prize_no); |
113 | $('#home_table_no').html(action.userInfo.table_no); | 113 | $('#home_table_no').html(action.userInfo.table_no); |
@@ -144,14 +144,9 @@ var action = { | @@ -144,14 +144,9 @@ var action = { | ||
144 | localId: localIds.toString(), // 需要上传的图片的ID,由chooseImage接口获得 | 144 | localId: localIds.toString(), // 需要上传的图片的ID,由chooseImage接口获得 |
145 | isShowProgressTips: 1, // 进度提示 | 145 | isShowProgressTips: 1, // 进度提示 |
146 | success: function(res) { | 146 | success: function(res) { |
147 | - $('.pic-avatar').attr('src', localIds); | ||
148 | - $('.pic-avatar').css({ | ||
149 | - width: '', | ||
150 | - height: '', | ||
151 | - 'margin-left': '', | ||
152 | - 'margin-top': '' | ||
153 | - }); | ||
154 | - action.loadImage('.pic-avatar', '.pic-avatar-wrap'); | 147 | + var imgHtml = '<img class="pic-avatar" src="' + localIds +'">'; |
148 | + $('.pic-avatar-wrap').html(imgHtml); | ||
149 | + action.loadImage(localIds, '.pic-avatar', '.pic-avatar-wrap'); | ||
155 | action.mediaId = res.serverId; // 返回图片的服务器端ID,即 mediaId | 150 | action.mediaId = res.serverId; // 返回图片的服务器端ID,即 mediaId |
156 | console.log('action.mediaId: ', action.mediaId); | 151 | console.log('action.mediaId: ', action.mediaId); |
157 | $('#upload_unavailable').hide(); | 152 | $('#upload_unavailable').hide(); |
@@ -171,42 +166,77 @@ var action = { | @@ -171,42 +166,77 @@ var action = { | ||
171 | } | 166 | } |
172 | }); | 167 | }); |
173 | }, | 168 | }, |
174 | - loadImage: function(dom, parent) { | 169 | + loadImage: function(src, dom, parent) { |
175 | var width = $(parent).width(); | 170 | var width = $(parent).width(); |
176 | - console.log('parent: ', width); | ||
177 | - $(dom).on('load', function() { | ||
178 | - var imgWidth = $(dom).width(); | ||
179 | - var imgHeight = $(dom).height(); | ||
180 | - console.log('dom--onload: ', $(dom)); | ||
181 | - console.log('width: ' + imgWidth); | ||
182 | - console.log('height: ' + imgHeight); | ||
183 | - var ratio = imgWidth / imgHeight; | ||
184 | - if (ratio > 1) { | ||
185 | - imgHeight = width; | ||
186 | - imgWidth = width * ratio; | ||
187 | - var margin = (imgWidth - width) / 2; | ||
188 | - $(dom).css({ | ||
189 | - width: imgWidth + 'px', | ||
190 | - height: imgHeight + 'px', | ||
191 | - 'margin-left': -margin + 'px' | ||
192 | - }); | ||
193 | - } else if (ratio < 1) { | ||
194 | - imgWidth = width; | ||
195 | - imgHeight = width / ratio; | ||
196 | - var margin = (imgHeight - width) / 2; | ||
197 | - $(dom).css({ | ||
198 | - width: imgWidth + 'px', | ||
199 | - height: imgHeight + 'px', | ||
200 | - 'margin-top': -margin + 'px' | ||
201 | - }); | ||
202 | - } else { | ||
203 | - $(dom).css({ | ||
204 | - width: width + 'px', | ||
205 | - height: width + 'px' | ||
206 | - }); | 171 | + console.log('parent-width: ', width); |
172 | + var img = new Image(); | ||
173 | + img.src = src; | ||
174 | + if (img.complete) { | ||
175 | + console.log('img complete'); | ||
176 | + } else { | ||
177 | + console.log('else'); | ||
178 | + img.onload = function() { | ||
179 | + console.log('img onload'); | ||
180 | + console.log('width: ' + img.width); | ||
181 | + console.log('height: ' + img.height); | ||
182 | + var ratio = img.width / img.height; | ||
183 | + if (ratio > 1) { | ||
184 | + img.height = width; | ||
185 | + img.width = width * ratio; | ||
186 | + var margin = (img.width - width) / 2; | ||
187 | + $(dom).css({ | ||
188 | + 'margin-left': -margin + 'px' | ||
189 | + }); | ||
190 | + } else if (ratio < 1) { | ||
191 | + img.width = width; | ||
192 | + img.height = width / ratio; | ||
193 | + var margin = (img.height - width) / 2; | ||
194 | + $(dom).css({ | ||
195 | + 'margin-top': -margin + 'px' | ||
196 | + }); | ||
197 | + } else { | ||
198 | + img.width = width; | ||
199 | + img.height = width; | ||
200 | + } | ||
207 | } | 201 | } |
208 | - }); | 202 | + } |
209 | }, | 203 | }, |
204 | + // loadImage: function(dom, parent) { | ||
205 | + // var width = $(parent).width(); | ||
206 | + // console.log('parent: ', width); | ||
207 | + // $(dom).on('load', function() { | ||
208 | + // var imgWidth = $(dom).width(); | ||
209 | + // var imgHeight = $(dom).height(); | ||
210 | + // console.log('dom--onload: ', $(dom)); | ||
211 | + // console.log('width: ' + imgWidth); | ||
212 | + // console.log('height: ' + imgHeight); | ||
213 | + // var ratio = imgWidth / imgHeight; | ||
214 | + // if (ratio > 1) { | ||
215 | + // imgHeight = width; | ||
216 | + // imgWidth = width * ratio; | ||
217 | + // var margin = (imgWidth - width) / 2; | ||
218 | + // $(dom).css({ | ||
219 | + // width: imgWidth + 'px', | ||
220 | + // height: imgHeight + 'px', | ||
221 | + // 'margin-left': -margin + 'px' | ||
222 | + // }); | ||
223 | + // } else if (ratio < 1) { | ||
224 | + // imgWidth = width; | ||
225 | + // imgHeight = width / ratio; | ||
226 | + // var margin = (imgHeight - width) / 2; | ||
227 | + // $(dom).css({ | ||
228 | + // width: imgWidth + 'px', | ||
229 | + // height: imgHeight + 'px', | ||
230 | + // 'margin-top': -margin + 'px' | ||
231 | + // }); | ||
232 | + // } else { | ||
233 | + // $(dom).css({ | ||
234 | + // width: width + 'px', | ||
235 | + // height: width + 'px' | ||
236 | + // }); | ||
237 | + // } | ||
238 | + // }); | ||
239 | + // }, | ||
210 | // 上传头像 | 240 | // 上传头像 |
211 | uploadImage: function() { | 241 | uploadImage: function() { |
212 | if (!action.mediaId) { | 242 | if (!action.mediaId) { |