<!DOCTYPE html>
<html lang='zh-cn'>
<head>
<title>Insert you title</title>
<meta name='description' content='this is my page'>
<meta name='keywords' content='keyword1,keyword2,keyword3'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel='stylesheet' type='text/css' href='./css/index.css' />
<script type='text/javascript' src='./js/jquery-1.12.1.min.js'></script>
<style type='text/css'>
html,body {
margin: 0; padding: 0;
} html {
height: 100%;
} body {
background: #000;
} #can {
display: block; margin: 25px auto;border-radius: 2px;background:#FFF;
}
</style>
<script type='text/javascript'>
$( function(){
var can = $('#can').get(0);
var oCan = can.getContext('2d');
var oImg = $('#img').get(0);
/*
图片预加载的方式:
在W3C HTML Image DOM 中当美使用一个<img/>标签时系统自动创建一个new Image()对象,这个对象包含诸多属性和时间其中可以为我们实现图片预加载的属性和事件
包括:
属性 :
complete
readyState : complete loading
onerror:
onload
*/
if(oImg.complete == 'true' || oImg.readyState == 'complete' || oImg.readyState == 'loading'){
drawImage();
}else{
oImg.onload = drawImage ;
}
function drawImage(){
/*
javascript demo code ...
*/
}
} );
</script>
</head>
<body>
<canvas id='can' width='500' height='450'>检测到您的浏览器版本过低,请升级您的浏览器版本以获取更好的用户体验...</canvas>
<img src = './images/demo.jpg'/>
</body>
</html>