javascript - 如何在javascript中放大/缩小页面
问题描述
我想在 Google Chrome 中制作一个放大/缩小页面的按钮。(就像我按 ctrl 和 + 或 ctrl 和 - 一样)。请帮我。我不想缩放元素(主体)。
解决方案
这是放大和缩小的方法。
function zoomIn(){
var body = document.querySelector("body");
var currWidth = body.clientWidth;
if(currWidth == 1000000){
alert("Maximum zoom-in level of 1 Million reached.");
} else{
body.style.width = (currWidth + 50) + "px";
}
}
function zoomOut(){
var body = document.querySelector("body");
var currWidth = body.clientWidth;
if(currWidth == 500000){
alert("Maximum zoom-out level reached.");
} else{
body.style.width = (currWidth - 50) + "px";
}
}
运行放大运行zoomIn()
缩小zoomOut()
推荐阅读
- reactjs - 如何从 azure ad 获取当前登录的用户角色?
- html - 当它们在一个 div 中时,如何将样式分别应用于每个字符?
- ios - associatedtype 协议一致性问题
- c# - 立即打开 excel,无需使用 interop.excel 将 excel 保存到本地路径
- php - 如何在不影响 SEO 的情况下将 HTML 包含在另一个 HTML 中?
- shell - 寻找更新项目内部环境变量的最佳实践
- javascript - 如何在 React Native 中“绘制”可触摸的分段环、曲线或弧线以构建现代组件
- amazon-web-services - AWS api 网关与 AWS SQS 集成中的具体格式消息属性是什么?
- mongodb - 安装在 ubuntu 上的 MongoDB 不工作(错误:活动失败)
- javascript - 从当前范围内的另一个文件执行函数