javascript - 如何防止一个子元素缩放
问题描述
如何在缩放.container时防止缩放#chart?
我想在用户调整浏览器窗口大小时缩放除一个 div (#chart) 之外的所有内容 (.container)。对于这个 div,我从 apexcharts.js 导入了一个图表,但由于缩放了这个元素,它不能正常工作。所以我想省略缩放这个特定的 div 以适应所有可用空间(它是一个响应图表)。我不知道该怎么做...
window.addEventListener('resize', () => resizeWindow());
const resizeWindow = () => {
const {innerWidth: width, innerHeight: height} = window;
if(width < 768) {
const scale = height/PANEL_HEIGHT;
document.documentElement.style.setProperty(SCALE_PROPERTY, scale);
return;
}
else {
const scale = Math.min(width/PANEL_WIDTH, height/PANEL_HEIGHT);
document.documentElement.style.setProperty(SCALE_PROPERTY, scale);
}
}
:root {
--scale-value: 1;
}
.panel {
height: 1000px;
width: 1600px;
position: absolute;
transform: scale(calc(var(--scale-value) * 0.9));
transform-origin: center;
}
<div class="container">
<div id="chart"></div>
</div>
解决方案
推荐阅读
- html - 花式下拉菜单,更改图标 onclick jquery
- java - 当我对依赖项进行一些 pom 更改时,Intellij 会自动下载。这个 mvn install 在后台运行吗?
- javascript - 从 JSP 调用 JS 函数
- javascript - 反应路由器,在查看路由之前将变量添加到url
- spring - RuntimeException 未在邮递员中显示错误消息
- java - 无法在 STS 版本 4.5.0 中添加 java 11 jre
- android - 如何连接 Unity 播放器首选项和 Android sharedPreferences?
- python - AWS Elastic Beanstalk - 更新应用程序后出现 502 Bad Gateway 错误
- reactjs - 如何使用钩子而不是使用反应和打字稿的上下文提供者?
- npm - npm 脚本无法正确启动业力测试