JavaScript 문자 아바타 구현

Jmnote (토론 | 기여)님의 2021년 9월 15일 (수) 02:11 판 (→‎개요)

1 개요

JavaScript 문자 아바타 구현
<style>
    .lavatar {
        width: 48px;
        height: 48px;
        line-height: 48px;
        font-size: 24px;
        text-align: center;
        color: #fff;
        float: left;
    }
</style>

<script type="module">
(async () => {
    const { default: ColorHash } = await import('https://cdnjs.cloudflare.com/ajax/libs/color-hash/2.0.1/color-hash.min.js');

    var colorHash = new ColorHash({lightness: 0.5, saturation: 0.7});

    function showLavatar(username) {
        var color = colorHash.hex(username);
        var initial = username.charAt(0);
        document.write("<div class='lavatar' style='background:" + color + "'>" + initial + "</div>");
    }

    showLavatar("Alice");
    showLavatar("Bob");
    showLavatar("Carol");
    showLavatar("한놈");
    showLavatar("두시기");
    showLavatar("석삼");
})()
</script>

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}