<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
{
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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |