From d03d461672aa8807cb61c0f729d8ef332c63632e Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 20 Mar 2012 16:49:47 +0000 Subject: [PATCH] Fixed problem with exponents in CSS values CSS doesn't like "translateY(1e-13px)" --- js/macros/zoomer.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/js/macros/zoomer.js b/js/macros/zoomer.js index 7bd484ef0..524d789b6 100644 --- a/js/macros/zoomer.js +++ b/js/macros/zoomer.js @@ -58,14 +58,19 @@ function hoverZoomer(macroNode,x,y) { if(macroNode.xFactor > 1) { macroNode.xFactor = 1; } - // And the 0->1 ration (from top to bottom) of the position of the touch down the screen + // And the 0->1 ratio (from top to bottom) of the position of the touch down the screen macroNode.yFactor = y/macroNode.windowHeight; // Now interpolate the scale macroNode.scale = (macroNode.minScale - 1) * macroNode.xFactor + 1; - // Apply the transform - document.body.style.webkitTransform = "translateY(" + window.scrollY * macroNode.xFactor + "px) " + - "scale(" + macroNode.scale + ") " + - "translateY(" + ((macroNode.windowHeight / macroNode.scale) - macroNode.bodyHeight) * macroNode.yFactor * macroNode.xFactor + "px)"; + // Apply the transform. The malarkey with .toFixed() is because otherwise we might get numbers in + // exponential notation (such as 5.1e-15) that are illegal in CSS + var preTranslateY = window.scrollY * macroNode.xFactor, + scale = macroNode.scale, + postTranslateY = ((macroNode.windowHeight / macroNode.scale) - macroNode.bodyHeight) * macroNode.yFactor * macroNode.xFactor; + var transform = "translateY(" + preTranslateY.toFixed(8) + "px) " + + "scale(" + scale.toFixed(8) + ") " + + "translateY(" + postTranslateY.toFixed(8) + "px)"; + document.body.style.webkitTransform = transform; } exports.macro = {