【问题标题】:125% Zoom on webpage [duplicate]125% 放大网页 [重复]
【发布时间】:2021-10-18 03:35:29
【问题描述】:

如何添加一个 js 函数,在加载时将网页缩放到 125%?

我找到了一种使用按钮的方法,但我希望网页在加载时自动缩放。

<button onclick="body.style.zoom='150%'">Zoom 150%</button>

我尝试像下面的代码一样将它放入body标签中,但它不起作用......

<body onload="body.style.zoom='150%'">

谢谢。

【问题讨论】:

  • 你可以使用document.body.style.zoom = "150%"

标签: javascript html


【解决方案1】:

css 解决方案:

body{
    zoom: 125%;
}

内联javascript解决方案:

<button
    onclick="document.getElementsByTagName('body')[0].style.zoom='150%'"
>Click to zoom
</button>

【讨论】:

    【解决方案2】:

    简单地抛弃 js 并使用 css

    <body style="zoom:150%;">
    

    <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    </head>
    <body style="zoom:150%;">
    <h1>My First Heading</h1>
    <p>My first paragraph.</p>
    
    </body>
    </html>

    【讨论】:

      猜你喜欢
      • 2017-07-10
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 2016-02-25
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多