Javascript 图像库变暗按钮
在“我的图像库”的右上角,有一个按钮,单击该按钮可创建一个使图像变暗的覆盖层。我希望能够在单击时打开和关闭它。我怎样才能做到这一点 这是我的密码Javascript 图像库变暗按钮,javascript,html,css,Javascript,Html,Css,在“我的图像库”的右上角,有一个按钮,单击该按钮可创建一个使图像变暗的覆盖层。我希望能够在单击时打开和关闭它。我怎样才能做到这一点 这是我的密码 而不是overlay.backgroundColor=dooverlay.style.backgroundColor=而不是overlay.backgroundColor=dooverlay.style.backgroundColor= btn.addEventListener("click", ()=> { var btnClass = b
而不是
overlay.backgroundColor=
dooverlay.style.backgroundColor=
而不是overlay.backgroundColor=
dooverlay.style.backgroundColor=
btn.addEventListener("click", ()=> {
var btnClass = btn.getAttribute("class");
if(btnClass === "dark") {
overlay.backgroundColor = "rgba(0,0,0,0.5)";
btn.textContent = "Lighten";
btn.setAttribute("class", "light");
} else if (btn.className != "dark") {
overlay.backgroundColor = "rgba(0,0,0,0)";
btn.textContent = "Darken";
btn.setAttribute("class", "dark");
}
})