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

 
(같은 사용자의 중간 판 10개는 보이지 않습니다)
14번째 줄: 14번째 줄:
     }
     }
</style>
</style>
<body></body>


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


     var colorHash = new ColorHash({lightness: 0.5, saturation: 0.7});
     var colorHash = new ColorHash({lightness: 0.5, saturation: 0.7});
33번째 줄: 33번째 줄:
     showLavatar("두시기");
     showLavatar("두시기");
     showLavatar("석삼");
     showLavatar("석삼");
})()
</script>
</script>
</syntaxhighlight>
</syntaxhighlight>

2021년 9월 15일 (수) 02:27 기준 최신판

1 개요[ | ]

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

<script type="module">
    import ColorHash from 'https://cdnjs.cloudflare.com/ajax/libs/color-hash/2.0.1/esm.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 }}