您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

canvas画矩形和svg画矩形的两种方法代码

2024/6/12 6:20:41发布19次查看
本篇文章给大家带来的内容是关于canvas画矩形和svg画矩形的两种方法代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
1.canvas画矩形
<!doctype html><html><head><!--canvas画矩形--><style>#huaban{border:1px solid;}</style><script></script><meta charset="utf-8"></head><body><canvas width="200" height="200" id="huaban"></canvas><script>var can=document.getelementbyid("huaban");//获得画板数据var con=can.getcontext('2d');//获得笔刷 con.fillstyle="red";//设置填充颜色 con.strokestyle="blue";//设置线条颜色 con.fillrect(10,10,100,100);//填充画矩形 con.strokerect(100,100,200,200);//线条画矩形</script></body></html>
2.svg画矩形
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect width="300" height="100"></rect> </svg>
rect 代表矩形;
rect 元素的 width 和 height 属性可定义矩形的高度和宽度;
圆角矩形:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect width="300" height="100" style="fill:deepskyblue;stroke-width:2;stroke:rgb(0,0,0);fill-opacity:0.5;stroke-opacity:0.9;opacity:0.5;" x="0" y="20" rx="20" ry="20"></rect> </svg>
css 的 fill-opacity 属性定义填充颜色透明度(合法的范围是:0 - 1);
css 的 stroke-opacity 属性定义边框颜色的透明度(合法的范围是:0 - 1);
css 的 opacity 属性定义整个元素的不透明度(合法的范围是:0 - 1);
svg中旋转的话可以用transform='rotate(45)
相关文章推荐:
jpg图片转换成svg文字路径动画的实例(附代码)
svg画图功能:svg实现画出一朵花(附代码)
以上就是canvas画矩形和svg画矩形的两种方法代码的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product