diff --git a/examples/Animated/RadialRainbows.html b/examples/Animated/RadialRainbows.html index 3de1a46f..00247d80 100644 --- a/examples/Animated/RadialRainbows.html +++ b/examples/Animated/RadialRainbows.html @@ -39,14 +39,10 @@ mouseDown = false; } - function onFrame() { - iterate(); - } - var grow = false; var vector = new Point(150, 0); - function iterate() { + function onFrame() { for (var i = 0, l = gradient.stops.length; i < l; i++) gradient.stops[i].color.hue -= 20; if (grow && vector.length > 300) { diff --git a/src/browser/DomElement.js b/src/browser/DomElement.js index b1d2cec8..975c5598 100644 --- a/src/browser/DomElement.js +++ b/src/browser/DomElement.js @@ -70,8 +70,9 @@ var DomElement = new function() { isVisible: function(el) { // See if the scrolled bounds intersect with the windows rectangle // which always starts at 0, 0 - return new Rectangle([0, 0], DomElement.getWindowSize()) - .intersects(DomElement.getBounds(el, false, true)); + return !DomElement.isInvisible(el) + && new Rectangle([0, 0], DomElement.getWindowSize()) + .intersects(DomElement.getBounds(el, false, true)); } }; }; diff --git a/src/ui/Key.js b/src/ui/Key.js index 858ca537..33d85cf6 100644 --- a/src/ui/Key.js +++ b/src/ui/Key.js @@ -70,7 +70,7 @@ var Key = this.Key = new function() { key = keys[keyCode] || character.toLowerCase(), handler = down ? 'onKeyDown' : 'onKeyUp', view = View.focused, - scope = view && view._scope, + scope = view && view.isVisible() && view._scope, tool = scope && scope.tool; keyMap[key] = down; if (tool && tool[handler]) { diff --git a/src/ui/View.js b/src/ui/View.js index 35a391f5..0e13b915 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -193,6 +193,17 @@ var View = this.View = Base.extend({ this._zoom = zoom; }, + /** + * Checks whether the view is currently visible within the current browser + * viewport. + * + * @return {Boolean} Whether the view is visible. + */ + isVisible: function() { + // TODO: Take bounds into account if it's not the full canvas? + return DomElement.isVisible(this._canvas); + }, + /** * @param {Point} point */