码迷,mamicode.com
首页 > Web开发 > 详细

HTML5 Canvas ( 线段端点的样式 ) lineCap

时间:2017-03-25 20:06:26      阅读:381      评论:0      收藏:0      [点我收藏+]

标签:pat   style   tle   doc   css   bsp   span   begin   strong   

<!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{
            margin: auto auto;
            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);
    
    /**
     * 线条顶点的样式
     */
    cxt.lineWidth = 40;
    cxt.strokeStyle = red;
    cxt.beginPath();
    cxt.moveTo(100, 100);
    cxt.lineTo(800, 300);
    cxt.lineCap = "butt"; //线段端点的样式
    cxt.stroke();
    
    cxt.beginPath();
    cxt.moveTo(100, 200);
    cxt.lineTo(800, 400);
    cxt.lineCap = "round"; //线段端点的样式
    cxt.stroke();
    
    cxt.beginPath();
    cxt.moveTo(100, 300);
    cxt.lineTo(800, 500);
    cxt.lineCap = "square"; //线段端点的样式
    cxt.stroke();
</script>

 

HTML5 Canvas ( 线段端点的样式 ) lineCap

标签:pat   style   tle   doc   css   bsp   span   begin   strong   

原文地址:http://www.cnblogs.com/lovling/p/6618077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!