Fabric.JS를 사용하여 Angular 2 어플리케이션의 캔버스에서 요소를 드래그합니다. 휴대 전화에서 응용 프로그램을 열면 항목을 드래그 할 때 상당한 지연이 있습니다. 처음 몇 초 동안 지체가 발생하지는 않지만 물건을 끌어 올리는 데 오래 걸리면 악화되고 악화됩니다. Fabric.JS를 각도 2로 사용할 때의 성능 문제
나는 각도이없이 Fabric.JS를 사용하여 테스트를하기로 결정, 나는이 세 가지 사각형 개체를 추가하고 아래의 코드 샘플에서 각도 2.를 사용하지 않을 경우 더 지연이 없다는 것을 발견 캔버스. 지연은이 세 가지 객체만으로도 거의 눈에 띄지 않지만 여러 가지 객체를 추가하면 실제로 나 빠지게됩니다.
내 지체 각도 2 구성 요소 :
import {Component, OnInit, ViewChild, ElementRef} from '@angular/core';
import 'fabric';
declare let fabric;
@Component({
selector: 'app-fabric-canvas',
template: `
<canvas #canvas width="800" height="800"></canvas>
`
})
export class FabricCanvasComponent implements OnInit {
@ViewChild('canvas') canvasRef:ElementRef;
private canvas: any;
private square1;
private square2;
private square3;
ngOnInit() {
this.canvas = new fabric.Canvas(this.canvasRef.nativeElement, { });
this.square1 = new fabric.Rect({
width: 50,
height:50,
left: 0,
top: 0,
fill:'red'
});
this.square2 = new fabric.Rect({
width: 50,
height:50,
left: 0,
top: 0,
fill:'blue'
});
this.square3 = new fabric.Rect({
width: 50,
height:50,
left: 0,
top: 0,
fill:'green'
});
this.canvas.add(this.square1);
this.canvas.add(this.square2);
this.canvas.add(this.square3);
}
}
각도 2를 사용하지 않는 및 지체되지 내 시험 :
<canvas id="canvas" width="800" height="800"></canvas>
<script>
var canvas = new fabric.Canvas('canvas');
var square1 = new fabric.Rect({
width: 50,
height:50,
left: 0,
top: 0,
fill:'red'
});
var square2 = new fabric.Rect({
width: 50,
height:50,
left: 0,
top: 0,
fill:'blue'
});
var square3 = new fabric.Rect({
width: 50,
height:50,
left: 0,
top: 0,
fill:'green'
});
canvas.add(square1);
canvas.add(square2);
canvas.add(square3);
</script>
질문은 : 왜 내가 경험하고있다 Fabric.JS를 Angular 2와 함께 사용하는 경우에만이 지연이 발생합니까? Fabric.JS를 Angular 2 구성 요소에서 가져 오거나 사용하는 방식에 문제가 있습니까?
나는 angular2 전문가가 아니지만 각도가 집중적 인 fps 의존적 앱을 실행할 장소가 아니라는 것을 알고있는 한 내가 탐구하지 않은 해결책이있다. 각도의 영역 밖에서 코드를 실행한다고합니다. [this] (https://angular.io/docs/ts/latest/api/core/index/NgZone-class.html)과 같은 것 –
팁 주셔서 감사합니다. 이것이 내가 필요한 것일 수도 있습니다. 나는 그것을 시도 할 것이다. – SnorreDan
안녕하세요. Fabric.js로 Angular 2의 좌석 예약 응용 프로그램을 구현했으며 1000 석 (사각형)의 경우에도 문제가 없습니다. 여기에 내 [Hello World Angular 2 + Fabric.js] (https://github.com/milanhlinak/hello-angular-fabric) 프로젝트가 있습니다. 이 프로젝트에서는 1000 개의 항목으로 테스트를했으며 모바일 장치에는 아무런 문제가 없습니다. –