<!doctype html>
<html>
<head>
<meta charset="utf-8">
</title>
</head>
<body><!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="/jqplot/excanvas.min.js"></script><![endif]-->
<script type="text/javascript">
var list=[];
var currentC;
var _e={};
var cricle = function(x,y,r){
this.x=x;
this.y=y;
this.r=r;
this.isCurrent=false;
this.drawC=function(ctx,x,y){
ctx.save();
ctx.beginPath();
ctx.moveTo(this.x,this.y-this.r);
ctx.arc(this.x,this.y,this.r,2*Math.PI,0,true);
if ((x && y && ctx.isPointInPath(x, y) && !currentC )||this.isCurrent) {
ctx.fillStyle = '#ff0000';
currentC=this;
this.isCurrent=true;
}else{
ctx.fillStyle = '#999999';
}
ctx.fill();
}
}
function draw(){
var canvas = document.getElementById('tutorial');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
for(var i=0;i<10;i++){
var c=new cricle(20*i,20*i,5*i);
c.drawC(ctx);
list.push(c);
}
}
}
function reDraw(e){
e=e||event;
var canvas = document.getElementById('tutorial');
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
canvas.width = canvas.width;
if (canvas.getContext){
var ctx = canvas.getContext('2d');
for(var i=0;i<list.length;i++){
var c=list[i];
c.drawC(ctx,x,y);
}
}
}
function show(e){
e=e||event;
var canvas = document.getElementById('tutorial');
var ctx = canvas.getContext('2d');
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
if(currentC){
currentC.x=parseInt(x+(x-currentC.x)/5);
currentC.y=parseInt(y+(y-currentC.y)/5);
}
_e=e;
}
window.οnlοad=function(){
var canvas = document.getElementById('tutorial');
draw();
canvas.οnmοusedοwn=function(e){
e=e||event;
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
if(currentC)
currentC.isCurrent=false;
currentC=null;
reDraw(e);
_e=e;
var showTimer=setInterval(function(e){
reDraw(e);
},10,_e);
canvas.οnmοusemοve=show;
document.οnmοuseup=function(){
if(currentC)
currentC.isCurrent=false;
currentC=null;
canvas.οnmοusemοve=null;
clearInterval(showTimer);
}
}
}
</script>
<style type="text/css">
canvas { border: 1px solid black; }
</style>
</head>
<body style="background:#eeeeee;">
<canvas id="tutorial" width="1000" height="550" style="z-index:100;display:block;position:absolute;"></canvas>
</body>
</html></body>
</html>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="/jqplot/excanvas.min.js"></script><![endif]-->
<script type="text/javascript">
var list=[];
var currentC;
var _e={};
var cricle = function(x,y,r){
this.x=x;
this.y=y;
this.r=r;
this.isCurrent=false;
this.drawC=function(ctx,x,y){
var c=document.getElementById("tutorial");
var cxt=c.getContext("2d");
var img = new Image()
img.src = "Untitled.jpg"
cxt.drawImage(img, 0, 0);
ctx.save();
ctx.beginPath();
ctx.arc(this.x,this.y,this.r,0,2*Math.PI,0,true);
if ((x && y && ctx.isPointInPath(x, y) && !currentC )||this.isCurrent) {
ctx.fillStyle = '#ff0000';
currentC=this;
this.isCurrent=true;
}else{
ctx.fillStyle = '#999999';
}
ctx.fill();
}
}
function draw(){
var canvas = document.getElementById('tutorial');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
for(var i=0;i<1;i++){
if(i == 0)
{
i = 5;
}
var c=new cricle(20*i,20*i,5*i);
c.drawC(ctx);
list.push(c);
if(i == 5)
{
i = 0;
}
}
}
}
function reDraw(e){
e=e||event;
var canvas = document.getElementById('tutorial');
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
canvas.width = canvas.width;
if (canvas.getContext){
var ctx = canvas.getContext('2d');
for(var i=0;i<list.length;i++){
var c=list[i];
c.drawC(ctx,x,y);
}
}
}
function show(e){
e=e||event;
var canvas = document.getElementById('tutorial');
var ctx = canvas.getContext('2d');
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
if(currentC){
currentC.x=parseInt(x+(x-currentC.x)/5);
currentC.y=parseInt(y+(y-currentC.y)/5);
}
_e=e;
}
window.οnlοad=function(){
var canvas = document.getElementById('tutorial');
draw();
canvas.οnmοusedοwn=function(e){
e=e||event;
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
if(currentC)
currentC.isCurrent=false;
currentC=null;
reDraw(e);
_e=e;
var showTimer=setInterval(function(e){
reDraw(e);
},10,_e);
canvas.οnmοusemοve=show;
document.οnmοuseup=function(){
if(currentC)
currentC.isCurrent=false;
currentC=null;
canvas.οnmοusemοve=null;
clearInterval(showTimer);
}
}
}
</script>
<style type="text/css">
canvas { border: 1px solid black; }
</style>
</head>
<body style="background:#eeeeee;">
<canvas id="tutorial" width="1000" height="550" style="z-index:100;display:block;position:absolute;"></canvas>
<!--script>
var c = document.getElementById("tutorial");
var cxt = c.getContext("2d");
var img = new Image()
img.src = "Untitled.jpg"
cxt.drawImage(img, 0, 0);
</script-->
</body>
</html>
自己修改后的
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="/jqplot/excanvas.min.js"></script><![endif]-->
<script type="text/javascript">
var list=[];
var currentC;
var _e={};
var cricle = function(x,y,r){
this.x=x;
this.y=y;
this.r=r;
this.isCurrent=false;
this.drawC=function(ctx,x,y){
var c=document.getElementById("tutorial");
var cxt=c.getContext("2d");
//背景色
cxt.fillStyle = '#000';
cxt.strokeStyle = '#fff';
cxt.fillRect(0,0,1000,550);
cxt.lineWidth = 1;
cxt.fill();
//刷图
var img = new Image()
img.src = "Untitled.jpg"
cxt.drawImage(img, 200, 0);
ctx.save();
ctx.beginPath();
ctx.arc(this.x,this.y,this.r,0,2*Math.PI,true);
if ((x && y && ctx.isPointInPath(x, y) && !currentC )||this.isCurrent) {
ctx.fillStyle = '#ff0000';
currentC=this;
this.isCurrent=true;
}else{
ctx.fillStyle = '#999999';
}
ctx.fill();
ctx.stroke();
/*ctx.beginPath();
ctx.arc(100,100,15,0,2*Math.PI,true);
ctx.stroke();*/
ctx.beginPath();
ctx.moveTo(100,100);
ctx.lineTo(this.x,this.y);
ctx.stroke();
ctx.strokeText("w3school.com.cn",10,90);
}
}
function draw(){
var canvas = document.getElementById('tutorial');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
for(var i=0;i<2;i++){
//ctx.save();
var c=new cricle(20*(i+1),20*(i+1),15);
c.drawC(ctx);
list.push(c);
//ctx.restore();
}
}
}
function reDraw(e){
e=e||event;
var canvas = document.getElementById('tutorial');
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
canvas.width = canvas.width;
if (canvas.getContext){
var ctx = canvas.getContext('2d');
for(var i=0;i<list.length;i++){
//ctx.save();
var c=list[i];
c.drawC(ctx,x,y);
//ctx.restore();
}
}
}
function show(e){
e=e||event;
var canvas = document.getElementById('tutorial');
var ctx = canvas.getContext('2d');
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
if(currentC){
currentC.x=parseInt(x+(x-currentC.x)/5);
currentC.y=parseInt(y+(y-currentC.y)/5);
}
_e=e;
}
window.οnlοad=function(){
var canvas = document.getElementById('tutorial');
draw();
canvas.οnmοusedοwn=function(e){
e=e||event;
var x = e.clientX - canvas.offsetLeft;
var y = e.clientY - canvas.offsetTop;
if(currentC)
currentC.isCurrent=false;
currentC=null;
reDraw(e);
_e=e;
var showTimer=setInterval(function(e){
reDraw(e);
},10,_e);
canvas.οnmοusemοve=show;
document.οnmοuseup=function(){
if(currentC)
currentC.isCurrent=false;
currentC=null;
canvas.οnmοusemοve=null;
clearInterval(showTimer);
}
}
}
</script>
<style type="text/css">
canvas { border: 1px solid black; }
</style>
</head>
<body style="background:#eeeeee ;">
<canvas id="tutorial" width="1000" height="550" style="z-index:100;display:block;position:absolute;"></canvas>
<script>
/*var c = document.getElementById("tutorial");
var cxt = c.getContext("2d");
var img = new Image()
img.src = "Untitled.jpg"
cxt.drawImage(img, 0, 0);*/
</script>
<br />
<br />
<br />
<div id="xycoordinates"></div>
</body>
</html>