為何不使用canvas.ooffsetLeft和offsetTop呢
?function windowTocanvas(x,y){
? ? ? ? ? ? var bbox = canvas.getBoundingClientRect();/* 獲取canvas的包圍盒對象*/
? ? ? ? ? ? return {x:x-bbox.left,y:y-bbox.top};
? ? ? ? }
為何不使用canvas.left和top呢,難道不能使用
?function windowTocanvas(x,y){
? ? ? ? ? ? var bbox = canvas.getBoundingClientRect();/* 獲取canvas的包圍盒對象*/
? ? ? ? ? ? return {x:x-bbox.left,y:y-bbox.top};
? ? ? ? }
為何不使用canvas.left和top呢,難道不能使用
2017-06-30
舉報
2017-07-06
offsetleft,會把盒子模型里的margin值也算進去這樣就無法得到精確的位置了。