canvas绘制矩形框
分类:实例代码
canvas绘制矩形框属于前端实例代码,有关更多实例代码大家可以查看。
本章节分享一段代码实例,它实现了绘制矩形框的效果。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> </head> <style type="text/css"> canvas{ border:dashed 2px #CCC } </style> <script type="text/javascript"> function $$(id){ return document.getElementById(id); } function pageLoad(){ var can = $$('can'); var cans = can.getContext('2d'); cans.strokeStyle = 'red'; cans.strokeRect(30,30,340,240); } window.onload=function(){ pageLoad(); } </script> <body> <canvas id="can" width="400px" height="300px"></canvas> </body> </html>
canvas绘制矩形框,这样的场景在实际项目中还是用的比较多的,关于canvas绘制矩形框就介绍到这了。