[ html drawImage 圖片預加載 ] canvas繪制圖片 drawImage 屬性實例演示之三--使用New Image()進行圖片預加載


 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     height: 100%;
17 }
18 
19 body {
20     background: #000;
21 }
22 
23 #can {
24     background: #FFF; display: block; margin: 25px auto; border-radius: 2px;
25 }
26 </style>
27 <script type='text/javascript'>
28     var oCan = null , oImg = null;
29     $( function(){
30         oCan = $( '#can' ).get( 0 ).getContext( '2d' );
31         var oImg = new Image();
32         oImg.src = './images/demoImg.jpg';
33         oImg.onload = function(){
34             oCan.drawImage( oImg , 0 , 0 , oImg.width / 2 , oImg.height / 2 );
35         };
36     } );
37 </script>
38 </head>
39 <body>
40     <canvas id='can' width='500' height='450'>檢測到您的瀏覽器版本過低請升級您的瀏覽器以獲取更好的使用體驗...</canvas>
41 </body>
42 </html>

 


免責聲明!

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



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