forked from lojjic/PIE
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all accesses of element dimensions into a new BoundsInfo object,…
… which queries the element dimensions once at the start of an update and caches that value through the update process. This prevents potentially dozens of reflows by the browser and gives a huge performance boost in IE8 particularly.
- Loading branch information
Jason Johnston
committed
Sep 1, 2010
1 parent
6b374bb
commit 04ed5d5
Showing
9 changed files
with
119 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Handles calculating, caching, and detecting changes to size and position of the element. | ||
* @constructor | ||
* @param {Element} el the target element | ||
*/ | ||
PIE.BoundsInfo = function( el ) { | ||
this.element = el; | ||
}; | ||
PIE.BoundsInfo.prototype = { | ||
|
||
_lastBounds: {}, | ||
|
||
positionChanged: function() { | ||
var last = this._lastBounds, | ||
bounds = this.getBounds(); | ||
return !last || last.x !== bounds.x || last.y !== bounds.y; | ||
}, | ||
|
||
sizeChanged: function() { | ||
var last = this._lastBounds, | ||
bounds = this.getBounds(); | ||
return !last || last.w !== bounds.w || last.h !== bounds.h; | ||
}, | ||
|
||
getLiveBounds: function() { | ||
var rect = this.element.getBoundingClientRect(); | ||
return { | ||
x: rect.left, | ||
y: rect.top, | ||
w: rect.right - rect.left, | ||
h: rect.bottom - rect.top | ||
}; | ||
}, | ||
|
||
getBounds: function() { | ||
return this._lockedBounds || this.getLiveBounds(); | ||
}, | ||
|
||
lock: function() { | ||
this._lockedBounds = this.getLiveBounds(); | ||
}, | ||
|
||
unlock: function() { | ||
this._lastBounds = this._lockedBounds; | ||
this._lockedBounds = null; | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters