From 27096d64cf7386e732e13b3c3228f293d88084c5 Mon Sep 17 00:00:00 2001 From: badlogic Date: Tue, 12 Sep 2017 11:32:38 +0200 Subject: [PATCH] [ts] updated viewport check in utils.js --- spine-ts/webgl/demos/utils.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spine-ts/webgl/demos/utils.js b/spine-ts/webgl/demos/utils.js index 3ddf94919..23289b135 100644 --- a/spine-ts/webgl/demos/utils.js +++ b/spine-ts/webgl/demos/utils.js @@ -25,13 +25,15 @@ var spineDemos = { } } - function checkElementVisible (demo) { - var rect = demo.canvas.getBoundingClientRect(); - var x = 0, y = 0; - var width = (window.innerHeight || document.documentElement.clientHeight); - var height = (window.innerWidth || document.documentElement.clientWidth); - demo.visible = rect.left < x + width && rect.right > x && rect.top < y + height && rect.bottom > y; - }; + function checkElementVisible(demo) { + const rect = demo.canvas.getBoundingClientRect(); + const windowHeight = (window.innerHeight || document.documentElement.clientHeight); + const windowWidth = (window.innerWidth || document.documentElement.clientWidth); + const vertInView = (rect.top <= windowHeight) && ((rect.top + rect.height) >= 0); + const horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0); + + demo.visible = (vertInView && horInView); + } spineDemos.setupRendering = function (canvas, renderFunc) { var demo = {canvas: canvas, renderFunc: renderFunc, visible: false};