从我的角度来看,我正在以正确的方式做任何事情。当页面加载时我开始我的脚本,我的语法没问题。我想的问题是init函数没有加载,有人能指出我在哪里犯了错误吗?
var canvas;
var ctx;
var x = 75;
var y = 50;
var r = 100;
var width = 400;
var height = 300;
var drag = false;
addEventListener("load",windowLoaded,false);
function windowLoaded(){
init();
console.log("beertje");
}
function init() {
canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
return setInterval(Circle, 10);
canvas.onmousedown = myDown;
canvas.onmouseup = myUp;
console.log("beertje");
}
function Circle(x,y,r) {
ctx.beginPath();
ctx.arc(x,y,r,0,Math.PI,true);
ctx.closePath();
ctx.fill();
}
function draw() {
clear();
arc(x,y,r,0,Math.PI,true);
ctx.fillStyle = "#444444";
arc(x - 15, y - 15, r, 0, Math.PI, true);
}
function myMove(e){
if (drag){
x = e.pageX - canvas.offsetLeft;
y = e.pageY - canvas.offsetTop;
}
}
function myDown(e){
if (e.pageX < x + 15 + canvas.offsetLeft && e.pageX > x - 15 +
canvas.offsetLeft && e.pageY < y + 15 + canvas.offsetTop &&
e.pageY > y -15 + canvas.offsetTop){
x = e.pageX - canvas.offsetLeft;
y = e.pageY - canvas.offsetTop;
drag = true;
canvas.onmousemove = myMove;
}
}
function myUp(){
drag = false;
canvas.onmousemove = null;
}