首页 > 代码库 > HTML5 Canvas ( 图形的阴影 ) shadowColor, shadowOffsetX, shadowOffsetY, shadowNlur

HTML5 Canvas ( 图形的阴影 ) shadowColor, shadowOffsetX, shadowOffsetY, shadowNlur

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>canvas</title>
    <script type="text/javascript" src="../js/jQuery.js"></script>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
            outline: none;
            border: none;
        }
        #canvas{
            width: 7rem;
            margin: .25rem 0 0 1.5rem;
            border: 1px solid black;
        }
    </style>
</head>
<body> 
    <canvas id="canvas" width="1000" height="600"></canvas>
</body>
</html>
<script type="text/javascript">
    /**
     * rem 布局初始化
     */
    $(html).css(font-size, $(window).width()/10);
    /**
     * 获取 canvas 画布
     * 获取 canvas 绘图上下文环境
     */
    var canvas = $(#canvas)[0];
    var cxt = canvas.getContext(2d);
    
    /**
     * 阴影
     * shadowColor: 阴影的颜色
     * shadowOffsetX: 横向偏移
     * shadowOffsetY: 纵向偏移
     * shadowNlur: 模糊程度
     */
    cxt.shadowColor = "red";
    cxt.shadowOffsetX = 20;
    cxt.shadowOffsetY = 20;
    cxt.shadowBlur = 0;
    cxt.fillRect(200, 200, 400, 200);
</script>

 

HTML5 Canvas ( 图形的阴影 ) shadowColor, shadowOffsetX, shadowOffsetY, shadowNlur