日期:2014-05-16 浏览次数:20446 次
function getCursorPosition(e){
var x;
var y;
if (e.pageX != undefined && e.pageY != undefined) {
x = e.pageX;
y = e.pageY;
}else{
//the position relativeto the docment
x = e.clientX + document.body.scrollLeft +
document.documentElement.scrollLeft;
y = e.clientY + document.body.scrollTop +
document.documentElement.scrollTop;
}
//coordiantes to the canvas
var c = document.getElementById("logo");
x -= c.offsetLeft;
y -= c.offsetTop;
//if the mouse position
if(x>=368 && x<=400 && y>=10 && y<=50){
c_context = c.getContext("2d");
//there have a block box to discovery the text "H"
c_context.fillStyle = "#323232";
c_context.beginPath();
c_context.moveTo(368,10);
c_context.lineTo(400,10);
c_context.lineTo(400,50);
c_context.lineTo(368,50);
c_context.fill();
//there have nine orange box instead if the text "H"
c_context.fillStyle = "#f99405";
for(i = 370 ;i<411; i+=14){
for(j=10; j<51;j+=14){
c_context.beginPath();
c_context.moveTo(i,j);
c_context.lineTo(i+13,j);
c_context.lineTo(i+13,j+13);
c_context.lineTo(i,j+13);
c_context.fill();
//the boxes move to anywhere they want
//这里是想加的代码 但不知道怎么写。(每画出一个小方块就按照预定的轨迹移动)
}
}
}
}