Authored by ccbikai

个人信息默认头像

... ... @@ -5,9 +5,12 @@
*/
var $ = require('jquery');
var $userAvatar = $('.user-avatar');
var myImage = new Image();
var myImage = new Image(),
avatar;
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 + ')');
};
... ...
... ... @@ -17,6 +17,14 @@
}
height: 80rem / $pxConvertRem;
border-bottom: 1px solid #e0e0e0;
.user-avatar {
width: 100%;
height: 100%;
background-image: image-url("me/index/user-avatar.png");
background-size: 100%;
}
span{
&:first-of-type{
color: #444;
... ...
{{> layout/header}}
<div class="personal-details">
<ul>
<li><span>头像</span><span><i class="head-portrait"><img class="user-avatar" src="{{ head_ico }}"></i></span></li>
<li><span>头像</span><span><i class="head-portrait"><span class="user-avatar" data-avatar="{{ head_ico }}"></span></i></span></li>
<li><span>昵称</span><span>{{ username }}</span></li>
<li><span>性别</span><span>{{ gender }}</span></li>
<li><span>生日</span><span>{{ birthday }}</span></li>
... ...