Skip to content

Commit fa2493a

Browse files
committed
Add isElInViewport method in CanvasView
1 parent 2f75e43 commit fa2493a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/canvas/view/CanvasView.js

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ module.exports = Backbone.View.extend({
1616
});
1717
},
1818

19+
20+
/**
21+
* Checks if the element is visible in the canvas's viewport
22+
* @param {HTMLElement} el
23+
* @return {Boolean}
24+
*/
25+
isElInViewport(el) {
26+
const rect = el.getBoundingClientRect();
27+
const frameRect = this.getFrameOffset(1);
28+
const rTop = rect.top;
29+
const rLeft = rect.left;
30+
return rTop >= 0 && rLeft >= 0 &&
31+
rTop <= frameRect.height && rLeft <= frameRect.width;
32+
},
33+
1934
/**
2035
* Update tools position
2136
* @private

0 commit comments

Comments
 (0)