Fix - Position issue of element on resize
Browse files
assets/scripts/src/overlay.js
CHANGED
@@ -11,6 +11,7 @@ export default class Overlay {
|
|
11 |
this.positionToHighlight = new Position({});
|
12 |
this.highlightedPosition = new Position({});
|
13 |
this.redrawAnimation = null;
|
|
|
14 |
|
15 |
this.draw = this.draw.bind(this);
|
16 |
|
@@ -54,6 +55,10 @@ export default class Overlay {
|
|
54 |
}
|
55 |
|
56 |
clear() {
|
|
|
|
|
|
|
|
|
57 |
this.document.body.removeChild(this.overlay);
|
58 |
}
|
59 |
|
@@ -148,5 +153,13 @@ export default class Overlay {
|
|
148 |
// cut out a chunk for the element to be visible out of it
|
149 |
this.overlay.width = width || this.window.innerWidth;
|
150 |
this.overlay.height = height || this.window.innerHeight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
}
|
152 |
}
|
|
|
11 |
this.positionToHighlight = new Position({});
|
12 |
this.highlightedPosition = new Position({});
|
13 |
this.redrawAnimation = null;
|
14 |
+
this.highlightedElement = null;
|
15 |
|
16 |
this.draw = this.draw.bind(this);
|
17 |
|
|
|
55 |
}
|
56 |
|
57 |
clear() {
|
58 |
+
// Cancel the existing animation frame if any
|
59 |
+
// remove the highlighted element and remove the canvas
|
60 |
+
this.window.cancelAnimationFrame(this.redrawAnimation);
|
61 |
+
this.highlightedElement = null;
|
62 |
this.document.body.removeChild(this.overlay);
|
63 |
}
|
64 |
|
|
|
153 |
// cut out a chunk for the element to be visible out of it
|
154 |
this.overlay.width = width || this.window.innerWidth;
|
155 |
this.overlay.height = height || this.window.innerHeight;
|
156 |
+
|
157 |
+
// If the highlighted element was there Cancel the
|
158 |
+
// existing animation frame if any and highlight it again
|
159 |
+
// as its position might have been changed
|
160 |
+
if (this.highlightedElement) {
|
161 |
+
this.window.cancelAnimationFrame(this.redrawAnimation);
|
162 |
+
this.highlight(this.highlightedElement);
|
163 |
+
}
|
164 |
}
|
165 |
}
|