javascript - 将所有背景更改为透明
问题描述
https://codepen.io/jayllopy/pen/bQgRPY
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft= "0";
document.body.style.backgroundColor = "white";
}
我有这个链接将所有背景更改为白色不透明度0.4,除了#main,bg颜色为红色
问:我想在 sidenav 打开时将#main 背景更改为 rgba(0,0,0,0.4)
解决方案
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
document.getElementById("main").style.backgroundColor = 'rgba(0,0,0,0.4)';
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft= "0";
document.body.style.backgroundColor = "white";
document.getElementById("main").style.backgroundColor = 'rgb(255,0,0)';
}
当你关闭它时它会变回红色。
推荐阅读
- javascript - 正则表达式匹配某些字符并排除某些字符但没有负前瞻
- javascript - Image onload not being called in vue
- c++ - unable to update root in Binary search tree
- java - 多线程/并发运行 selenium Windows
- php - how to display multiple meta_key / meta_values per SQL query in Wordpress
- excel - 使用 VBA 抓取 div 类信息
- wordpress - Cannot change site address or url in WP settings
- python - Scapy ARP 函数在运行时没有给出正确的输出
- ios - 没有设备,因为活动方案没有目标
- javascript - 您可以将带有 wasm 文件的模块加载到 create-react-app 中吗?