Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width" />
  <title>fadeOutEffect</title>
  <link rel="stylesheet" href="style.css" />
</head>
<body>
  <div id="target" align="center">
   Click on the button to activate fadeOutEffect()
  </div>
  <input type="button" onclick="fadeOutEffect()" value="fadeOutEffect">
  <script src="script.js"></script>
</body>
</html>
 
#target
{
 width: 80%;
 height: 300px;
 background: white;
 border: 1px solid black;
 text-align: center;
 line-height: 300px;
 overflow: scroll;
}
body
{
 background: red;
}
input
{
 -webkit-appearance: none;
}
.zerOpac
{
opacity: 0;
}
.oneOpac
{
opacity: 0.1;
}
.twoOpac
{
opacity: 0.2;
}
.thrOpac
{
opacity: 0.3;
}
.fouOpac
{
opacity: 0.4;
}
.fivOpac
{
opacity: 0.5;
}
.sixOpac
{
opacity: 0.6;
}
.sevOpac
{
opacity: 0.7;
}
.eigOpac
{
opacity: 0.8;
}
.ninOpac
{
opacity: 0.9;
}
 
function fadeOutEffect()
{
 var fadeTarget = document.getElementById("target");
 var fadeEffect = setInterval(function() {
  if (fadeTarget.style.opacity <= 0.1)
  {
   fadeTarget.style.opacity -= 0.1;
  }
  else
  {
   clearInterval(fadeEffect);
  }
 }, 200);
}
//   fadeOutTest is my attempt to 
// apply different opacity for
// each class then use setInterval
// to change the target's class
// but it doesn't work!
 
function fadeOutTest()
{
 var targetElem = document.getElementById("target");
 var currOpac = 10;
 var fadeEff = setInterval(function() {
  if (currOpac = 10)
  {
   currOpac--;
   targetElem.class = "ninOpac";
  }
  else if (currOpac = 9)
  {
   currOpac--;
   targetElem.class = "eigOpac";
  }
  else if (currOpac = 8)
  {
   currOpac--;
   targetElem.class = "sevOpac";
  }
  else if (currOpac = 7)
  {
   currOpac--;
   targetElem.class = "sixOpac";
  }
  else if (currOpac = 6)
  {
   currOpac--;
   targetElem.class = "fivOpac";
  }
  else if (currOpac = 5)
  {
   currOpac--;
   targetElem.class = "fouOpac";
  }
  else if (currOpac = 4)
  {
   currOpac--;
   targetElem.class = "thrOpac";
  }
  else if (currOpac = 3)
  {
   currOpac--;
   targetElem.class = "twoOpac";
  }
  else if (currOpac = 1)
  {
   currOpac--;
   targetElem.class = "ninOpac";
  }
  else
  {
   targetElem.class = "zerOpac";
   clearInterval(fadeEff);
  }
 }, 200);
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
Black3800pro
0viewers