本文主要包含HTML5,CSS3,锯齿等相关知识,佚名 希望在学习及工作中可以帮助到您
最近通过敲Html5+Css3,分享一些自己认为值得学习的知识,分享给大家。
如何绘制一个锯齿状的矩形:如图
我们知道绘制图形可以用canvas ,canvas是HTML5出现的新标签,用于在网页上绘制图形,H5的canvas使用Javascript在网页上绘制图形。
如上锯齿状的矩形,就是用canvas绘制的。
实现代码:
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>锯齿图</title>
- <script type="text/javascript">
- window.addEventListener("load", eventWindowLoaded, false);
- function eventWindowLoaded(){
- var x,y;
- var theCanvas = document.getElementById("canvas");
- var context = theCanvas.getContext("2d");
- context.strokeStyle = '#CB9A61';
- context.lineWidth=10;
- context.strokeRect(10, 10, theCanvas.width-20, theCanvas.height-20);
- context.fillStyle = "#FFFFFF";
- for(x=5;x<=canvas.width;xx=x+10){
- context.beginPath();
- context.arc(x,5,5,0,Math.PI*2,true);
- context.arc(x,canvas.height-5,5,0,Math.PI*2,true);
- context.closePath();
- context.fill();
- }
- for(y=5;y<=canvas.height;yy=y+10){
- context.beginPath();
- context.arc(5,y,5,0,Math.PI*2,true);
- context.arc(canvas.width-5,y,5,0,Math.PI*2,true);
- context.closePath();
- context.fill();
- }
- }
- </script>
- </head>
- <body>
- <