我們知道繪制圖形可以用canvas ,canvas是HTML5出現(xiàn)的新標簽,用于在網(wǎng)頁上繪制圖形,H5的canvas使用Javascript在網(wǎng)頁上繪制圖形。
如上鋸齒狀的矩形,就是用canvas繪制的。
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <!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>
- <div style="position: absolute; top: 100px; left: 100px;">
- <canvas id="canvas" width="400" height="170" top=50px; left=50px;>
- </div>
- </body>
- </html>
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <!DOCTYPE HTML>
- <html lang="en">
-
- <body style="margin: 0 0 0 0;">
- <div id="1" style="background-color:#727171;width:50px;height:20px;float:left" ></div>
- <div id="2" style="float:left;border-width:10px;border-color:#727171 #9fa0a0 #9fa0a0 #727171;border-style:solid"></div>
- <div id="3" style="background-color:#9fa0a0;width:50px;height:20px;float:left" ></div>
- </body>
- </html>
后續(xù)繼續(xù)總結(jié)有關(guān)HTML和CSS的一些知識,前臺的知識看上去簡單,其實是個細致活,可以鍛煉一個人的耐心。從簡單到復(fù)雜,從入門到深入,一點點提高自己。