Commit ed2d4ab4ac0aef6478837054947571117c226c8e

Authored by 程雨佳
2 parents d0392759 3d894794
lottery.html
... ... @@ -37,7 +37,8 @@
37 37 .main-left .avatar-img {position: relative; width: 488px;height: 488px;border-radius: 50%;overflow: hidden;}
38 38 .main-left .avatar-list {position: absolute;top: 0;left: 0;}
39 39 .winner {width: 488px;height: 488px;border-radius: 50%;overflow: hidden;}
40   - .main-left .avatar-item {float: left;width: 488px;height: 488px;border-radius: 50%;}
  40 + .main-left .avatar-item-wrap {float: left;width: 488px;height: 488px;border-radius: 50%;overflow: hidden;}
  41 + .main-left .avatar-item {width: 488px;}
41 42 .main-left .avatar-bg {position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: url('./img/pc/avatar_bg.png') no-repeat;background-size: 100% 100%;}
42 43 .user-info {display: flex;font-size: 55px;color: #FFCD7E;}
43 44 .user-info .label {width: 292px;text-align: right;}
... ... @@ -83,7 +84,9 @@
83 84 <div class="avatar">
84 85 <div class="avatar-img">
85 86 <div class="avatar-list clearfix">
86   - <img class="avatar-item" src="./img/pc/default_avatar.png">
  87 + <div class="avatar-item-wrap">
  88 + <img class="avatar-item" src="./img/pc/default_avatar.png">
  89 + </div>
87 90 </div>
88 91 </div>
89 92 <div class="winner hide">
... ...
lottery.js
... ... @@ -52,6 +52,38 @@ let action = {
52 52 $('.result-title').html(action.prizeList[action.curPrizeIndex].prize_name);
53 53 }
54 54 },
  55 + loadImage: function(dom, parent) {
  56 + var width = $(parent).width();
  57 + $(dom).on('load', function() {
  58 + var imgWidth = $(dom).width();
  59 + var imgHeight = $(dom).height();
  60 + var ratio = imgWidth / imgHeight;
  61 + if (ratio > 1) {
  62 + imgHeight = width;
  63 + imgWidth = width * ratio;
  64 + var margin = (imgWidth - width) / 2;
  65 + $(dom).css({
  66 + width: imgWidth + 'px',
  67 + height: imgHeight + 'px',
  68 + 'margin-left': -margin + 'px'
  69 + });
  70 + } else if (ratio < 1) {
  71 + imgWidth = width;
  72 + imgHeight = width / ratio;
  73 + var margin = (imgHeight - width) / 2;
  74 + $(dom).css({
  75 + width: imgWidth + 'px',
  76 + height: imgHeight + 'px',
  77 + 'margin-top': -margin + 'px'
  78 + });
  79 + } else {
  80 + $(dom).css({
  81 + width: width + 'px',
  82 + height: width + 'px'
  83 + });
  84 + }
  85 + });
  86 + },
55 87 // 获取奖项列表
56 88 getPrizeList: function() {
57 89 let url = '/apicp.PrizeList.php';
... ... @@ -113,18 +145,16 @@ let action = {
113 145 let nameStr = '';
114 146 let prizeNoStr = '';
115 147 this.userList.map(user => {
116   - if (user.headimg) {
117   - imgStr += '<img class="avatar-item" src="' + user.headimg + '">';
118   - } else {
119   - imgStr += '<img class="avatar-item" src="' + defaultAvatar + '">';
120   - }
  148 + var userAvatar = user.headimg ? user.headimg : defaultAvatar;
  149 + imgStr += '<div class="avatar-item-wrap"><img class="avatar-item" src="' + userAvatar + '"></div>';
121 150 nameStr += '<span class="scroll-item">' + user.realname + '</span>';
122 151 prizeNoStr += '<span class="scroll-item">' + user.prize_no + '</span>';
123 152 });
124 153 $('.avatar-list').html(imgStr);
125 154 $('.user-name .scroll-list').html(nameStr);
126 155 $('.user-no .scroll-list').html(prizeNoStr);
127   - let imgListWidth = parseInt($('.avatar-list .avatar-item').css('width')) * this.userList.length + 'px';
  156 + this.loadImage('.avatar-list .avatar-item', '.avatar-list .avatar-item-wrap');
  157 + let imgListWidth = parseInt($('.avatar-list .avatar-item-wrap').css('width')) * this.userList.length + 'px';
128 158 $('.avatar-list').css('width', imgListWidth);
129 159 let nameListWidth = parseInt($('.user-name .scroll-item').css('width')) * this.userList.length + 'px';
130 160 $('.user-name .scroll-list').css('width', nameListWidth);
... ... @@ -142,7 +172,7 @@ let action = {
142 172 $('.stop-btn').show();
143 173  
144 174 // 开始抽奖动画
145   - imgTimer = this.lotteryAnimation($('.avatar-list'), '.avatar-item', 244);
  175 + imgTimer = this.lotteryAnimation($('.avatar-list'), '.avatar-item-wrap', 244);
146 176 nameTimer = this.lotteryAnimation($('.user-name .scroll-list'), '.scroll-item', 146);
147 177 prizeNoTimer = this.lotteryAnimation($('.user-no .scroll-list'), '.scroll-item', 146);
148 178 },
... ... @@ -179,7 +209,7 @@ let action = {
179 209 $('.continue-btn, .start-btn').hide();
180 210  
181 211 // 开始抽奖动画
182   - imgTimer = this.lotteryAnimation($('.avatar-list'), '.avatar-item', 244);
  212 + imgTimer = this.lotteryAnimation($('.avatar-list'), '.avatar-item-wrap', 244);
183 213 nameTimer = this.lotteryAnimation($('.user-name .scroll-list'), '.scroll-item', 146);
184 214 prizeNoTimer = this.lotteryAnimation($('.user-no .scroll-list'), '.scroll-item', 146);
185 215 },
... ... @@ -222,6 +252,7 @@ let action = {
222 252 $('.winner .avatar-item').attr('src', userAvatar);
223 253 $('.winner-name').html(this.currentUser.realname);
224 254 $('.winner-no').html(this.currentUser.prize_no);
  255 + action.loadImage('.winner .avatar-item', '.winner');
225 256  
226 257 // 更新中奖名单模板
227 258 action.updateResultTmpl();
... ...
mobile.html
... ... @@ -133,6 +133,24 @@
133 133 .dialog-reverse-btn {background: url('./img/mobile/dialog_btn_cancel.png') no-repeat;background-size: 100% 100%;color: #CF3727;}
134 134 .dialog-close {position: absolute;top: -.6rem;right: .26rem;width: .76rem;height: .76rem;background: url('./img/mobile/dialog_close.png') no-repeat;background-size: 100% 100%;}
135 135  
  136 + @media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
  137 + .home {padding-bottom: 3.5rem;}
  138 + .home-vote-btn {bottom: 2.1rem;}
  139 + .home-barrage-wrap {padding-bottom: .5rem;}
  140 + .bottom-btn {padding-bottom: .2rem;}
  141 + }
  142 + @media only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) {
  143 + .home {padding-bottom: 3.5rem;}
  144 + .home-vote-btn {bottom: 2.1rem;}
  145 + .home-barrage-wrap {padding-bottom: .5rem;}
  146 + .bottom-btn {padding-bottom: .2rem;}
  147 + }
  148 + @media only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) {
  149 + .home {padding-bottom: 3.5rem;}
  150 + .home-vote-btn {bottom: 2.1rem;}
  151 + .home-barrage-wrap {padding-bottom: .5rem;}
  152 + .bottom-btn {padding-bottom: .2rem;}
  153 + }
136 154 .no-auth {width: 100%;height: 100vh;display: flex;flex-direction: column;justify-content: center;align-items: center;font-size: .32rem;color: #000;}
137 155 .no-auth-icon {width: 3rem;margin-bottom: .3rem;}
138 156 .no-auth-text {padding-bottom: 2rem;}
... ... @@ -230,8 +248,9 @@
230 248 type="text"
231 249 placeholder="发条弹幕试试"
232 250 maxlength="50"
  251 + onfocus="action.onFocus()"
233 252 oninput="action.toggleBtnState()"
234   - onblur="action.resetPosition()">
  253 + onblur="action.onBlur()">
235 254 <div class="send-btn">发送</div>
236 255 </div>
237 256 </div>
... ...
mobile.js
... ... @@ -311,15 +311,35 @@ var action = {
311 311 // 发送弹幕
312 312 initBarrage: function() {
313 313 var socket = io(socketUrl);
314   -
  314 +
315 315 $('.send-btn').on('click', function() {
316 316 if ($('.barrage-input').val() != '') {
317 317 socket.emit('barrage', $('.barrage-input').val());
  318 + action.showToast('发送成功');
318 319 $('.barrage-input').val('');
319 320 $('.send-btn').removeClass('active');
320 321 }
321 322 });
322 323 },
  324 + onFocus: function() {
  325 + var width = window.screen.width;
  326 + var height = window.screen.height;
  327 + if ((width == 375 && height == 812) || (width == 414 && height == 896)) {
  328 + $('.home').css('padding-bottom', '3rem');
  329 + $('.home-vote-btn').css('bottom', '1.6rem');
  330 + $('.home-barrage-wrap').css('padding-bottom', '0');
  331 + }
  332 + },
  333 + onBlur: function() {
  334 + var width = window.screen.width;
  335 + var height = window.screen.height;
  336 + if ((width == 375 && height == 812) || (width == 414 && height == 896)) {
  337 + $('.home').css('padding-bottom', '3.5rem');
  338 + $('.home-vote-btn').css('bottom', '2.1rem');
  339 + $('.home-barrage-wrap').css('padding-bottom', '0.5rem');
  340 + }
  341 + this.resetPosition();
  342 + },
323 343 resetPosition: function () {
324 344 var currentPosition, timer;
325 345 var speed = 1; // 页面滚动距离
... ...