Authored by ccbikai

头像延迟加载

... ... @@ -6,14 +6,17 @@
var $ = require('jquery');
var $userAvatar = $('.user-avatar'),
$listItem = $('.list-item');
var myImage = new Image();
var myImage = new Image(),
avatar;
require('../product/recommend-for-you.js');
require('../product/suspend-cart.js');
myImage.src = $userAvatar.attr('src');
myImage.onerror = function() {
$userAvatar.attr('src', 'http://static.dev.yohobuy.com/img/me/index/user-avatar.png');
// 部分老用户没有头像,显示默认头像
avatar = $userAvatar.data('avatar');
myImage.src = avatar;
myImage.onload = function() {
$userAvatar.css('background-image', 'url(' + avatar + ')');
};
$('.yoho-page').on('touchstart', '.list-item, .type-item', function() {
... ...
... ... @@ -25,6 +25,8 @@
height: pxToRem(126px);
border-radius: 50%;
border: pxToRem(6px) solid #a7a8a9;
background-image: image-url("me/index/user-avatar.png");
background-size: 100%;
}
.username {
... ...
... ... @@ -3,7 +3,7 @@
<div class="my-header">
{{#isLogin}}
<a class="user-info" href="/home/mydetails">
<img class="user-avatar" src="{{head_ico}}">
<span class="user-avatar" data-avatar="{{head_ico}}"></span>
<span class="username">{{profile_name}}</span>
{{#vip_info}}
<span class="vip-icon vip-{{next_level}}"></span>
... ...