Skip to content

Commit 46cc8b6

Browse files
committed
Fix z-index ordering bug
1 parent 443fd17 commit 46cc8b6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Renderer.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
_html2canvas.Renderer = function(parseQueue, options){
2+
function sortZindex(a, b) {
3+
if (a === 'children') {
4+
return -1;
5+
} else if (b === 'children') {
6+
return 1;
7+
} else {
8+
return a - b;
9+
}
10+
}
211

312
// http://www.w3.org/TR/CSS21/zindex.html
413
function createRenderQueue(parseQueue) {
@@ -16,8 +25,9 @@ _html2canvas.Renderer = function(parseQueue, options){
1625
childrenDest = specialParent; // where children without z-index should be pushed into
1726

1827
if (node.zIndex.ownStacking) {
19-
// '!' comes before numbers in sorted array
20-
contextForChildren = stub.context = { '!': [{node:node, children: []}]};
28+
contextForChildren = stub.context = {
29+
children: [{node:node, children: []}]
30+
};
2131
childrenDest = undefined;
2232
} else if (isPositioned || isFloated) {
2333
childrenDest = stub.children = [];
@@ -39,7 +49,7 @@ _html2canvas.Renderer = function(parseQueue, options){
3949
})(parseQueue);
4050

4151
function sortZ(context) {
42-
Object.keys(context).sort(function(a, b) { return a - b; }).forEach(function(zi) {
52+
Object.keys(context).sort(sortZindex).forEach(function(zi) {
4353
var nonPositioned = [],
4454
floated = [],
4555
positioned = [],

0 commit comments

Comments
 (0)