<!DOCTYPE html>
<html lang="zh-cn" dir="ltr">
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1.0,user-scalable=no" name="viewport">
<title>canvas 测试模板</title>
<style media="screen">
html, body{
width: 100%;
height: 100%;
background: #ccc;
padding: 0px;
margin: 0px;
overflow: hidden;
}
canvas{
width: 400px;
height: 150px;
background: #fff;
margin: 100px;
}
div{
text-align: center;
}
</style>
</head>
<body>
<div class="">
<canvas id="canvas" width="400" height="150"></canvas>
</div>
</body>
<script type="text/javascript">
var canvas = document.getElementById('canvas')
var ctx = canvas.getContext('2d')
var ratio = window.devicePixelRatio
canvas.width = canvas.clientWidth * ratio
canvas.height = canvas.clientHeight * ratio
var width = canvas.width
var height = canvas.height
ctx.moveTo(10,10)
ctx.lineTo(390,10)
ctx.stroke()
ctx.moveTo(10,20.5)
ctx.lineTo(390,20.5)
ctx.stroke()
function loop() {
requestAnimFrame( loop );
}
</script>
</html>