"JavaScript 문자 아바타 구현"의 두 판 사이의 차이

태그: 되돌려진 기여
태그: 되돌려진 기여
14번째 줄: 14번째 줄:
     }
     }
</style>
</style>
 
<script src='https://cdnjs.cloudflare.com/ajax/libs/color-hash/2.0.1/esm.min.js'></script>
<script type="module">
<script type="module">
     import { ColorHash } from 'https://cdnjs.cloudflare.com/ajax/libs/color-hash/2.0.1/esm.min.js';
     const ColorHash = window.ColorHash;
     var colorHash = new ColorHash({lightness: 0.5, saturation: 0.7});
     var colorHash = new ColorHash({lightness: 0.5, saturation: 0.7});



2021년 9월 15일 (수) 02:21 판

1 개요

JavaScript 문자 아바타 구현
<style>
    .lavatar {
        width: 48px;
        height: 48px;
        line-height: 48px;
        font-size: 24px;
        text-align: center;
        color: #fff;
        float: left;
    }
</style>
<script src='https://cdnjs.cloudflare.com/ajax/libs/color-hash/2.0.1/esm.min.js'></script>
<script type="module">
    const ColorHash = window.ColorHash;
    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 }}