标签:path getc code end 上下 支持 默认 base 90度
canvas可以在页面中设定一个区域,再利用JavaScript动态地绘制图像。
<canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext(‘2d‘); //2d用单引用括起来 } </script> </body>
<!doctype html> <html> <head> <meta charset="utf-8"> <title>JavaScript之Canvas</title> </head> <body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext(‘2d‘); //2d用单引用括起来 //获取图像的数据URL var imgURL = canvas.toDataURL("image/png"); //默认图片格式为png,也可以自定义设置格式。 //显示图片 var image = document.createElement("img"); //添加一个img元素 image.src = imgURL; //将获取的图像的URL赋值给src属性 document.body.appendChild(image); //将元素添加到页面中 } </script> </body> </html>
<!doctype html> <html> <head> <meta charset="utf-8"> <title>JavaScript之Canvas</title> </head> <body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext(‘2d‘); //2d用单引用括起来 if (canvas.getContext) { var context = canvas.getContext("2d"); //2d用单引用括起来 context.fillStyle = "red"; // 填充颜色为红色 context.strokeStyle = "blue"; //描边颜色为蓝色 } } </script> </body> </html>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); context.fillStyle = "red"; // 指定填充颜色为红色 context.fillRect(10, 10, 150, 150); //用指定的颜色填充矩形 } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //2d用单引用括起来 context.strokeStyoe = "yellow"; // 描边颜色为蓝色 context.lineWidth = 4; //指定描边线的宽度 context.strokeRect(50, 50, 120, 120); //用指定的颜色描边矩形 } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //2d用单引用括起来 //描边矩形 context.strokeStyoe = "yellow"; // 描边颜色为蓝色 context.lineWidth = 4; //指定描边线的宽度 context.strokeRect(50, 50, 120, 120); //用指定的颜色描边矩形 //填充矩形 context.fillStyle = "red"; context.fillRect(50, 50, 120, 120); } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //2d用单引用括起来 //描边矩形 context.strokeStyoe = "yellow"; // 描边颜色为蓝色 context.lineWidth = 4; //指定描边线的宽度 context.strokeRect(50, 50, 120, 120); //用指定的颜色描边矩形 //填充矩形 context.fillStyle = "red"; context.fillRect(150, 150, 120, 120); } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //2d用单引用括起来 //描边矩形 context.strokeStyoe = "yellow"; // 描边颜色为蓝色 context.lineWidth = 4; //指定描边线的宽度 context.strokeRect(50, 50, 120, 120); //用指定的颜色描边矩形 //填充矩形 context.fillStyle = "red"; context.fillRect(150, 150, 120, 120); //消除指定大小的区域 context.clearRect(110, 110, 30, 30); } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //开始绘制新路径 context.beginPath(); context.arc(50, 50, 40, 0, 2*Math.PI, false); context.closePath(); //关闭路径 context.fillStyle = "red"; //以填充方式绘制圆 context.fill(); } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //开始绘制新路径 context.beginPath(); context.beginPath(); context.moveTo(100, 100); //绘制起点 context.arcTo(50, 50, 10, 200, 200); context.closePath(); context.strokeStyle = "red"; context.stroke(); } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //开始绘制新路径 context.beginPath(); context.moveTo(30, 30); //画线的起点 context.lineTo(200, 200); //终点 context.closePath(); context.strokeStyle = "red"; context.stroke(); } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //开始绘制新路径 context.beginPath(); context.arce(20, 20, 200, 200); context.closePath(); context.strokeStyle = "red"; context.stroke(); } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); context.fillStyle = "red"; context.font = "bold 26px"; //字体样式 context.textAlign = "statr"; //对齐方式为左对齐 context.textBaseline = "top"; //基线 context.fillText("你好", 100, 100, 200); } </script> </body>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); context.beginPath(); //绘制外圆 context.arc(100, 100, 99, 0, 2*Math.PI, false); //绘制内圆 context.moveTo(194, 100); context.arc(100, 100, 94, 0, 2*Math.PI, false); context.translate(100, 100); //变换原点,为后面绘制时针、分针做准备 //绘制分针 context.moveTo(0, 0); //绘制直线的起点 context.lineTo(0, -85); //至直线的终点 //绘制时针 context.moveTo(0, 0); context.lineTo(-65, 0); //描边绘制钟表 context.stroke(); } </script> </body>
<script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); context.beginPath(); //绘制外圆 context.arc(100, 100, 99, 0, 2*Math.PI, false); //绘制内圆 context.moveTo(194, 100); context.arc(100, 100, 94, 0, 2*Math.PI, false); context.translate(100, 100); //变换原点,为后面绘制时针、分针做准备 context.rotate(90); //不用像HTML中的变换一样带单位 //绘制分针 context.moveTo(0, 0); //绘制直线的起点 context.lineTo(0, -85); //至直线的终点 //绘制时针 context.moveTo(0, 0); context.lineTo(-65, 0); //描边绘制钟表 context.stroke(); } </script> </body>
<!doctype html> <html> <head> <meta charset="utf-8"> <title>JavaScript之Canvas</title> </head> <body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); context.fillStyle = "blue"; //先将fillStyle设置为蓝色 context.save(); //保存此时的属性 context.fillStyle = "yellow"; //再将fillStyle设置为黄色 context.translate(100, 100); //变换,将原点设置到(100, 100)这个位置 context.save(); //再保存此时的属性 context.fillStyle = "red"; // 将fillStyle设置为红色 context.save(); //第一次restore(),此时将矩形绘制为红色,且原点(0, 0)的实际坐标为(100, 100) context.restore(); //第二次restore(),此时将矩形绘制为黄色,且原点(0, 0)的实际坐标为(100, 100) context.restore(); //第三次restore(); 此时将矩形绘制为蓝色,这是最上级设置的属性,且此时的原点(0, 0)的实际坐标为(0, 0) context.restore(); context.fillRect(50, 50, 300, 300, false); } </script> </body> </html>
<body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //设置阴影的属性 context.shadowOffsetX = 10; context.shadowOffsetY = 20; context.shadowBlur = 2; context.shadowColor = "blue"; //绘制矩形 context.fillStyle = "red"; context.fillRect(10, 10, 109, 109); } </script> </body>
<!doctype html> <html> <head> <meta charset="utf-8"> <title>JavaScript之Canvas</title> </head> <body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //定义一个渐变对象 var gradient = context.createLinearGradient(30, 30, 200, 200); //为这个对象设置渐变颜色 gradient.addColorStop(0, "white"); gradient.addColorStop(1, "black"); //绘制一个矩形作为参考 context.fillStyle = "orange"; context.fillRect(20, 20, 200, 200); //把fillStyle或者strokeStyle设置为这个渐变对象 context.fillStyle = gradient; context.fillRect(30, 30, 200, 200); } </script> </body> </html>
<!doctype html> <html> <head> <meta charset="utf-8"> <title>JavaScript之Canvas</title> </head> <body> <canvas id="canvas" width="400" height="300">抱歉,您的浏览器不支持canvas元素</canvas> <script> var canvas = document.getElementById("canvas"); //检测浏览器是否支持canvas 该方法是否存在 取得上下文对象 if (canvas.getContext) { var context = canvas.getContext("2d"); //定义一个径向渐变对象 var gradient = context.createRadialGradient(57, 57, 10, 57, 57, 30); //为这个对象设置渐变颜色 gradient.addColorStop(0, "white"); gradient.addColorStop(1, "blue"); //结束颜色也就是矩形的颜色 //把fillStyle或者strokeStyle设置为这个渐变对象 context.fillStyle = gradient; context.fillRect(10, 10, 100, 100); } </script> </body> </html>
标签:path getc code end 上下 支持 默认 base 90度
原文地址:http://blog.csdn.net/h15882065951/article/details/70232080