欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!

stroke是HTML5 canvas中的一个方法,stroke()方法可以用于绘制当前路径。

stroke()方法会实际地绘制出通过 moveTo() 和 lineTo()方法定义的路径。默认颜色是黑色。

提示:可以使用 strokeStyle属性来绘制另一种颜色/渐变。

语法:

1

context.stroke();

示例:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

<!DOCTYPE html>

<html>

 

    <head>

        <meta charset="UTF-8">

    </head>

 

    <body>

        <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">

        Your browser does not support the HTML5 canvas tag.

        </canvas>

 

        <script>

            var c = document.getElementById("myCanvas");

            var ctx = c.getContext("2d");

            ctx.beginPath();

            ctx.moveTo(20, 20);

            ctx.lineTo(20, 100);

            ctx.lineTo(70, 100);

            ctx.strokeStyle = "green";

            ctx.stroke();

        </script>

 

    </body>

 

</html>

效果图:

1.jpg

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h57483.shtml