js 画直线,管用

来源:互联网 发布:windows激活工具kms 编辑:程序博客网 时间:2024/04/28 09:53

<html>
<head>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
<script type="text/javascript">
window.onload = function() {
  draw();
};
function draw() {
 
  var canvas = document.getElementById('canvassample');
 
  if ( ! canvas || ! canvas.getContext ) {
    return false;
  }
 
  var ctx = canvas.getContext('2d');
  ctx.beginPath(); 
ctx.fillStyle = 'red';
ctx.font = 'bold 20px sans-serif';
ctx.textBaseline = 'top';
ctx.fillText ('Hello Canvas!', 0, 0);
ctx.strokeStyle = 'red';
  ctx.lineWidth = 4;
  ctx.moveTo(20, 60);
  ctx.lineTo(1200, 60);
  ctx.closePath();
  ctx.stroke();
}
</script>
</head>
<body>
 <div width ="500">
   <canvas id="canvassample"></canvas>
  
  </div>

</body>
</html>


 
 

原创粉丝点击