首页 > 解决方案 > 如何在javascript中放大/缩小页面

问题描述

我想在 Google Chrome 中制作一个放大/缩小页面的按钮。(就像我按 ctrl 和 + 或 ctrl 和 - 一样)。请帮我。我不想缩放元素(主体)。

标签: javascripthtmlzooming

解决方案


这是放大和缩小的方法。

                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()


推荐阅读