简体   繁体   中英

Why isn't this simple Javascript concatenation working?

I tried all of the following, but none of them work:

iframe.style[transform] = 'scale('+(scale)+', 1) translate(-'+(0-scale)+'%, 0)';

iframe.style[transform] = 'scale('+(scale)+', 1) translate(-'+(-scale)+'%, 0)';

var translate = 0-scale;
iframe.style[transform] = 'scale('+(scale)+', 1) translate(-'+translate+'%, 0)';

var translate = 0-scale;
iframe.style[transform] = 'scale('+(scale)+', 1) translate(-'+translate.toString+'%, 0)';

However, it does work if I do this:

iframe.style[transform] = 'scale('+(scale)+', 1) translate(-0%, 0)';

Why shouldn't it work? I'm using Firefox 7 on Windows 7

没关系,但是您是否尝试过:

iframe.style[transform] = "scale(" + scale.toString() + ", 1); translate(-" + translate.toString() + "%, 0);";

The problem is that it may generate invalid syntax. Here:

'translate(-'+(0-scale)+'%, 0)';
           ^      ^
           |      |____ possible negative number
           |
           |___________ literal minus sign

may generate the following string:

translate(--0%, 0);
           ^
           |___________ double minus, which is invalid CSS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM