我嘗試使用標準方法獲取CssClass的GWT元素的大小,但它返回0;domElement.getClientWidth()和domElement.getClientHeight()返回0
Canvas canvas = Canvas.createIfSupported();
if(canvas == null){
/*alert code*/
}
Element e = canvas.getElement();
canvas.getElement().setClassName(canvasElement);
Context2d context = canvas.getContext2d();
int clientWidth = e.getClientWidth();
/*draw logic there*/
clientWidth是0
CSS類:
.canvasElement{
position: absolute;
left:10px;
top:10px;
width:40px;
height:30px;
}
在哪個時刻元件尺寸將被計算的?我如何捕捉瞬間?
Html需要您將canvas元素轉換爲html –