angular - 每当我的画布加载时,它只需要全宽而不是全高
问题描述
所以我的画布只需要全宽而不是全高。
我尝试使画布全高和全宽的组件:
export class AimComponent implements OnInit {
@ViewChild('canvas') myCanvas: ElementRef;
public context: CanvasRenderingContext2D;
ngOnInit() {
this.ngViewInit();
}
ngViewInit(){
this.context =
(<HTMLCanvasElement>this.myCanvas.nativeElement).getContext('2d');
this.draw();
}
draw() {
this.myCanvas.nativeElement.width = document.body.clientWidth;
this.myCanvas.nativeElement.height = document.body.clientHeight;
}
}
解决方案
使用window.innerWith
andwindow.innerHeight
而不是document.body.clientWidth/clientHeight
,我能够解决这个问题。
推荐阅读
- javascript - 从 'angularfire2/database' 导入 {AngularFireDatabase, FirebaseListObservable}
- android - Pdf 数据在 Android 上显示为空白
- pentaho - Pentaho - 如何用另一个值填充整个列?
- java - 为什么带有字符串编码参数的扫描仪构造函数不会抛出 UnsupportedEncodingException?
- android - 如何将每个坐标存储到二维数组 Android
- openedge - 如何在progress 4gl上以中文将数据存储在数据库中?
- javascript - 在不同的浏览器上出现不同的行为
- c - 如何在 Windows 上从 C 中的另一个程序启动一个独立程序(在单独的控制台窗口中)?
- java - 如何通过 websocket 将消息从非 web java 应用程序发送到 angular 应用程序?
- ios - 旋转动画发生时,UIImageView 未保留其中心