Fix - Canvas elements keep adding
Browse files
assets/scripts/src/overlay.js
CHANGED
@@ -33,19 +33,26 @@ export default class Overlay {
|
|
33 |
this.window = window;
|
34 |
this.document = document;
|
35 |
|
36 |
-
this.
|
37 |
this.setSize();
|
38 |
}
|
39 |
|
40 |
/**
|
41 |
* Prepares the overlay
|
42 |
*/
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
const overlay = this.document.createElement('canvas');
|
45 |
|
46 |
this.overlay = overlay;
|
47 |
this.context = overlay.getContext('2d');
|
48 |
|
|
|
49 |
this.overlay.style.pointerEvents = 'none';
|
50 |
this.overlay.style.background = 'transparent';
|
51 |
this.overlay.style.position = 'fixed';
|
|
|
33 |
this.window = window;
|
34 |
this.document = document;
|
35 |
|
36 |
+
this.resetOverlay();
|
37 |
this.setSize();
|
38 |
}
|
39 |
|
40 |
/**
|
41 |
* Prepares the overlay
|
42 |
*/
|
43 |
+
resetOverlay() {
|
44 |
+
// Check and remove the canvas if it already exists
|
45 |
+
const canvasOverlay = this.document.getElementById('sholo-canvas-overlay');
|
46 |
+
if (canvasOverlay && canvasOverlay.parentNode) {
|
47 |
+
canvasOverlay.parentNode.removeChild(canvasOverlay);
|
48 |
+
}
|
49 |
+
|
50 |
const overlay = this.document.createElement('canvas');
|
51 |
|
52 |
this.overlay = overlay;
|
53 |
this.context = overlay.getContext('2d');
|
54 |
|
55 |
+
this.overlay.id = 'sholo-canvas-overlay';
|
56 |
this.overlay.style.pointerEvents = 'none';
|
57 |
this.overlay.style.background = 'transparent';
|
58 |
this.overlay.style.position = 'fixed';
|