Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 图像库变暗按钮_Javascript_Html_Css - Fatal编程技术网

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=
do
overlay.style.backgroundColor=
而不是
overlay.backgroundColor=
do
overlay.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"); 
  }
})