[ html 繪圖 translate ] canvas繪圖屬性translate 設置畫布中心點屬性實例演示


 1 <!DOCTYPE html>
 2 <html lang='zh-cn'>
 3 <head>
 4 <title>Insert you title</title>
 5 <meta name='description' content='this is my page'>
 6 <meta name='keywords' content='keyword1,keyword2,keyword3'>
 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 8 <link rel='stylesheet' type='text/css' href='./css/index.css' />
 9 <script type='text/javascript' src='./js/jquery-1.12.1.min.js'></script>
10 <style type='text/css'>
11 html,body {
12     margin: 0; padding: 0;
13 }
14 
15 html {
16     background: #999; height: 100%;
17 }
18 
19 #can {
20     background: #FFF; display: block; margin: 75px auto; border-radius: 2px;
21 }
22 </style>
23 <script type='text/javascript'>
24     $( function(){
25         var oCan = $( '#can' ).get( 0 ).getContext( '2d' );
26         oCan.beginPath();
27         oCan.arc( 250 , 250 , 100 , 0 , 360 * Math.PI / 180 , false ); /* 現在的基准點是 canvas畫布的頂點(0,0),所以在調用arc()坐標點是(250,250) */
28         /* 
29             上面寫法的替代方法:
30             oCan.translate(250,250);    // 這種方法和上面方法還是有不同的,這種方法是將整個畫布的起始點全部移動到(250,250)位置,兒上面的只是在(250,250)的位置畫個圓
31             oCan.arc( 0 , 0 , 100 , 0 , 360 * Math.PI / 180 , false );
32                 
33          */
34         oCan.lineWidth = 1;
35         oCan.strokeStyle = '#F00';
36         oCan.stroke();
37         oCan.closePath();
38     } );
39     function getId( id ){
40         return document.getElementById( id );
41     }
42 </script>
43 </head>
44 <body>
45     <canvas id='can' width='500' height='500'>您的瀏覽器版本過低,請您更換瀏覽器以獲取更好的用戶體驗...</canvas>
46 </body>
47 </html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM