letterColoredAvatar

Display first letter on color like Gmail do for avatar.


Keywords
js, javascript, android, gmail, avatar, color, letter
Install
bower install letterColoredAvatar

Documentation

Letter Colored Avatar

Display first letter on color like Gmail do. Basic script to do quickly the job. Made for webkit but work on IE>=8 and without jquery.

capture d ecran 2015-06-10 23 42 27

Usage

Basic usage of the script:

Create a author block:

<div class="authorAvatar" data-name="Thomas P."></div>
<div class="authorAvatar" data-name="thomas@scullwm.com"></div>
<div class="authorAvatar" data-name="Jean Paul"></div>

Basic style to adapt for your case (no background color here) :

div.authorAvatar {
    width: 48px;
    height: 48px;
    display:table-cell;
    vertical-align:middle;
    text-align: center;
    color: white;
    font-weight: 100;
    line-height: 48px;
    font-size: 40px;
}

Transform your author block:

$('.authorAvatar').each(function(){
    coloredAvatar = letterColoredAvatar.display($(this).data('name'));
    $(this).css('background', coloredAvatar.color);
    $(this).text(coloredAvatar.firstLetter);
});