kamrify commited on
Commit
f5ebead
·
1 Parent(s): d5e94aa

Fix - Memory leak, animation frame never cancelled

Browse files
assets/scripts/src/overlay.js CHANGED
@@ -141,10 +141,14 @@ export default class Overlay {
141
  document.body.appendChild(this.overlay);
142
  }
143
 
144
- // @todo: do not requestAnimationFrame once final highlight position has been reached
145
-
146
- // Stage a new animation frame
147
- this.redrawAnimation = this.window.requestAnimationFrame(this.draw);
 
 
 
 
148
  } else {
149
  this.document.body.removeChild(this.overlay);
150
  }
 
141
  document.body.appendChild(this.overlay);
142
  }
143
 
144
+ // Stage a new animation frame only if the position has not been reached
145
+ // of the alpha has not yet fully reached fully required opacity
146
+ if (
147
+ !this.positionToHighlight.equals(this.highlightedPosition) ||
148
+ this.overlayAlpha.toFixed(2) !== this.opacity.toFixed(2)
149
+ ) {
150
+ this.redrawAnimation = this.window.requestAnimationFrame(this.draw);
151
+ }
152
  } else {
153
  this.document.body.removeChild(this.overlay);
154
  }
assets/scripts/src/position.js CHANGED
@@ -24,4 +24,11 @@ export default class Position {
24
  canHighlight() {
25
  return this.left < this.right && this.top < this.bottom;
26
  }
 
 
 
 
 
 
 
27
  }
 
24
  canHighlight() {
25
  return this.left < this.right && this.top < this.bottom;
26
  }
27
+
28
+ equals(position) {
29
+ return this.left.toFixed(3) === position.left.toFixed(3) &&
30
+ this.right.toFixed(3) === position.right.toFixed(3) &&
31
+ this.top.toFixed(3) === position.top.toFixed(3) &&
32
+ this.bottom.toFixed(3) === position.bottom.toFixed(3);
33
+ }
34
  }