You might be able to use the CSS zoom
property - supported in IE 5.5+, Opera, and Safari 4, and Chrome
document.body.style.zoom = 2
(2)transform scale
该scale()
函数由一个或两个值指定,这些值表示要在每个方向上应用的缩放量。
注意:
transform转换的基准位置属性为transform-origin,transform-origin属性默认值为上下左右中间位置,即:
transform-origin:50% 50% 0
为防止页面顶部看不到,可以对transform-origin进行重新设置:
transform-origin: center top;
代码示例:
<script type="text/JavaScript">
var size = 1.0;
function zoomout() {
size = size + 0.1;
set();
}
function zoomin() {
size = size - 0.1;
set();
}
function set() {
//document.body.style.cssText = document.body.style.cssText + '; -webkit-transform: scale(' + size + ');-webkit-transform-origin: 0 0;';
//document.body.style.cssText = document.body.style.cssText + '; -webkit-transform: scale(' + size + '); ';
//$(body).css("width","120%);
document.body.style.zoom = size;
document.body.style.cssText += '; -moz-transform: scale(' + size + ');-moz-transform-origin: 0 0; '; //
}
</script>
zoom vs scale:
Transform is more predictable than zoom across browsers.
Zoom affects positioning differently in different browsers.
example: position:absolute; left:50px; zoom: 50%;
- IE will not change the
left
value at all. - Chrome will change the left value to
25px
. Effectively it does doleft = left * zoom
. But DevTools Computed Values in DevTools will still displayleft: 50px
, even though that is effectively not true due to the zoom.
Transform is handled the same way in all browsers (as far as I can tell).
example: position:absolute; left:50px; transform: scale(0.5)
left
would effectively be set to25px
in both Chrome and IE. (again, computed values will still not reflect this, it will displayleft:50px
)- To avoid changing the
left
value, simply usetransform-origin: 0 0
. That will ensure left is still 50px.