javascript - 为什么放大和缩小功能在使用 jquery 的 firefox 中不能正常工作?

标签 javascript jquery html css firefox

我正在放大,我们在单击按钮时使用 jquery。

请查看截图:https://nimb.ws/ZSxTbW

在 chrome 中,它工作正常,但在 firefox 中,它不能正常工作,并且设计周围都有空白。

请查看截图:https://nimb.ws/SeX0sw

请帮我把它剪短

这是我的代码:

$('#In').on('click', function () {
    if (navigator.userAgent.indexOf('Firefox') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox') + 8)) >= 3.6) {//Firefox  
        var step = 0.02;
        currFFZoom += step;
        $('body').css('MozTransform', 'scale(' + currFFZoom + ')');
        save_zoom_level(currFFZoom);
    } else {
        var step = 2;
        currIEZoom += step;
        $('body').css('zoom', ' ' + currIEZoom + '%');
        save_zoom_level(currIEZoom);
    }
});

$('#Out').on('click', function () {
    if (navigator.userAgent.indexOf('Firefox') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox') + 8)) >= 3.6) {//Firefox  
        var step = 0.02;
        currFFZoom -= step;
        $('body').css('MozTransform', 'scale(' + currFFZoom + ')');
        save_zoom_level(currFFZoom);

    } else {
        var step = 2;
        currIEZoom -= step;
        $('body').css('zoom', ' ' + currIEZoom + '%');
        save_zoom_level(currIEZoom);
    }
});

最佳答案

我认为您不需要进行这么多检查。属性 transform: scale(1.5) 应该适用于所有没有 vendor 前缀的浏览器。

您可以执行以下操作。

function zoomIn() {
  var element = document.getElementById("content");
  element.classList.add("zoomIn");
}

function zoomOut() {
 var element = document.getElementById("content");
  element.classList.remove('zoomIn').add("zoomOut");
}
.content {
  width: 200px;
  height: 200px;
  background: #eab600;
  margin-top: 50px;
}

.zoomOut {
  transform: scale(0.9);
}

.zoomIn {
  transform: scale(1.5);
}
  <button onclick="zoomIn()">Zoom In</button>
  <button onclick='zoomOut()'>Zoom Out</button>
  
  <div id='content' class='content'></div>

关于javascript - 为什么放大和缩小功能在使用 jquery 的 firefox 中不能正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58036377/

相关文章:

javascript - 如何通过 react 中的组件传递变量的值?

javascript - 无法通过 AJAX 将数组发送到 php?

html - 如何让 IE7 在悬停时覆盖另一个图像

html - 停止 css 目标受后退按钮的影响

jquery - 当前表的重复行

html - IE7 的 CSS 宽度 : inline-block not working even after hacks

javascript - Knexjs 将 mysql 时间戳、日期时间列作为 Javascript 日期对象返回

javascript - 优化半小时间隔数组的排序时间

javascript - 隐藏源 CSS 代码

javascript - 通过单击按钮打开特定的 KendoUI 窗口