html5做圆角

来源:互联网 发布:淘宝上的补漆笔好用吗 编辑:程序博客网 时间:2024/04/28 07:07
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3.   <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5.     <meta http-equiv="Content-Language" content="zh-cn" />  
  6.     <title>画一个圆角图</title>  
  7.     <script type="text/javascript" src="jquery-1.4.min.js"></script>  
  8.     <script type="text/javascript"><!--   
  9.        
  10.     $(function(){   
  11.         var elem = $("#myCanvas")[0];   
  12.         if (!elem || !elem.getContext) {   
  13.             return;   
  14.         }   
  15.   
  16.         //CanvasRenderingContext2D   
  17.         var ctx = elem.getContext('2d');   
  18.         ctx.fillStyle   = '#00f';   
  19.         ctx.strokeStyle = '#0f0';   
  20.         ctx.lineWidth   = 10;   
  21.         ctx.globalAlpha   = 1;   
  22.         //lineCap指定线条的末端如何绘制,round这个值指定了线段应该带有一个半圆形的线帽,半圆的直径等于线段的宽度,并且线段在端点之外扩展了线段宽度的一半。   
  23.         ctx.lineCap = "round";   
  24.         //lineJoin 属性说明如何绘制交点。值 "round" 说明定点的外边缘应该和一个填充的弧接合,这个弧的直径等于线段的宽度。"   
  25.         ctx.lineJoin = "round";   
  26.   
  27.         ctx.beginPath();   
  28.         ctx.moveTo(10, 10);   
  29.         ctx.lineTo(200, 10);   
  30.         ctx.lineTo(200, 200);   
  31.         ctx.lineTo(10, 200);   
  32.         ctx.lineTo(10, 10);   
  33.         //ctx.fill();   
  34.         ctx.stroke();   
  35.         ctx.closePath();   
  36.     });   
  37.     // --></script>  
  38.   </head>  
  39.   <body>  
  40.     <canvas id="myCanvas" width="300" height="300">您的浏览器不支持HTML5元素</canvas>  
  41.   </body>  
  42. </html>