這些代碼不能畫出線條
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
? ? <canvas id="canvas" width="1024" height="768" style="border:1px solid #aaa;display:block;margin:50px auto;"></canvas>
? ?
<body>
?<script>
window.onload=function(){
var canvas=document.getElementById("canvas");
canvas.wdith=1024
canvas.height=768
var cantext=canvas.getContext("2d")
context.moveTo(100,100)
context.lineTo(700,700)
context.stroke()
}
</script>
</body>
</html>
2016-04-26
1---canvas元素沒放到body里,你放在body外面。
2---context.move后面的都錯了,你聲明的是var cantext=canvas.getContext("2d"),所以要用cantext.moveTo,cantext.lineTo,cantext.stroke
ps:既然你的canvas已經(jīng)有width,height屬性了為什么js里還要聲明一次。(js里面你的width寫錯了)
2016-04-04
var cantext=canvas.getContext("2d") 注意這里的變量名 和下面的不一樣哦