Skip to content

Commit 65746bd

Browse files
committed
coding optimizations
1 parent 16d3bef commit 65746bd

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

src/Parse.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,9 @@ _html2canvas.Parse = function (images, options) {
316316

317317
function setZ(element, stack, parentStack){
318318
var newContext,
319-
position = stack.cssPosition,
320-
zIndex = getCSS(element, 'zIndex'),
319+
isPositioned = stack.cssPosition !== 'static',
320+
zIndex = isPositioned ? getCSS(element, 'zIndex') : 'auto', // z-index only applies to positioned elements.
321321
opacity = getCSS(element, 'opacity'), // can't use stack.opacity because it's blended
322-
isPositioned = position !== 'static',
323322
isFloated = getCSS(element, 'cssFloat') !== 'none';
324323

325324
// https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context
@@ -329,15 +328,11 @@ _html2canvas.Parse = function (images, options) {
329328
// elements with an opacity value less than 1. (See the specification for opacity),
330329
// on mobile WebKit and Chrome 22+, position: fixed always creates a new stacking context, even when z-index is "auto" (See this post)
331330

332-
// z-index only applies to positioned elements.
333-
// however, firefox may return the value set in CSS even if it's not positioned
334-
if (!isPositioned) { zIndex = 0 ;}
335331
stack.zIndex = newContext = h2czContext(zIndex);
336332
newContext.isPositioned = isPositioned;
337333
newContext.isFloated = isFloated;
338334

339-
if (!parentStack || (zIndex !== 'auto' && isPositioned) ||
340-
(opacity && Number(opacity) < 1)) {
335+
if (zIndex !== 'auto' || opacity < 1) {
341336
newContext.ownStacking = true;
342337
}
343338

@@ -967,7 +962,6 @@ _html2canvas.Parse = function (images, options) {
967962

968963
var ctx = h2cRenderContext((!parentStack) ? documentWidth() : bounds.width , (!parentStack) ? documentHeight() : bounds.height),
969964
stack = {
970-
el: element, // very useful when debugging
971965
ctx: ctx,
972966
opacity: setOpacity(ctx, element, parentStack),
973967
cssPosition: getCSS(element, "position"),

src/Renderer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ _html2canvas.Renderer = function(parseQueue, options){
88
rootContext = (function buildStackingContext(rootNode) {
99
var rootContext = {};
1010
function insert(context, node, specialParent) {
11-
var zi = node.zIndex.zindex,
11+
var zi = (node.zIndex.zindex === 'auto') ? 0 : Number(node.zIndex.zindex),
1212
contextForChildren = context, // the stacking context for children
1313
isPositioned = node.zIndex.isPositioned,
1414
isFloated = node.zIndex.isFloated,
1515
stub = {node: node},
1616
childrenDest; // where children without z-index should be pushed into
1717

18-
if (zi === 'auto') { zi = 0; }
19-
zi = Number(zi);
2018
if (!context[zi]) { context[zi] = []; }
2119
if (node.zIndex.ownStacking) {
2220
contextForChildren = stub.context = { 0: [{node:node}]};

0 commit comments

Comments
 (0)