canvas一周一练 -- canvas绘制立体文字(2)

运行效果:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <canvas id="drawing" width="800" height="600">A drawing of someing!</canvas>
    <script type="text/javascript">
        var drawing = document.getElementById('drawing');
        if(drawing.getContext) {
            //绘制立体文字
            var context = drawing.getContext('2d');
            context.fillStyle = 'Purple';
            context.textAlign = 'center';
            context.textBaseline = 'middle';
            context.font = 'bold 100px Arial';
            context.fillText('', 290, 90);
            context.globalAlpha = 0.7;

            context.font = 'bold 80px Arial';
            context.fillText('', 380, 90);
            context.globalAlpha = 0.6;

            context.font = 'bold 70px Arial';
            context.fillText('', 205, 90);
            context.globalAlpha = 0.6;

            context.font = 'bold 60px Arial';
            context.fillText('', 450, 90);
            context.globalAlpha = 0.5;

            context.font = 'bold 60px Arial';
            context.fillText('', 140, 90);
            context.globalAlpha = 0.5;

            context.font = 'bold 40px Arial';
            context.fillText('', 500, 90);
            context.globalAlpha = 0.4;

            context.font = 'bold 40px Arial';
            context.fillText('', 95, 90);
            context.globalAlpha = 0.4;

            context.font = 'bold 20px Arial';
            context.fillText('', 530, 90);
            context.globalAlpha = 0.3;

            context.font = 'bold 20px Arial';
            context.fillText('', 65, 90);
            context.globalAlpha = 0.3;
        }

    </script>
</body>
</html>

 

posted @ 2017-07-18 11:43  张不丢  阅读(705)  评论(0编辑  收藏  举报