我的代码是这样的:
<body>
<div id="divId">
<canvas id="tabletId" height="500px" width="500px"></canvas>
</div>
</body>
然后在js中获取canvas到浏览器的距离是这么写的:
var canvas = document.getElementById("tabletId");
var ctx = canvas.getContext("2d");
var height = canvas.offsetTop;
var width = canvas.offsetLeft;
console.log(width + "------" + height);
执行出来的结果是0 ----- 0。
这是为什么呀?求教