I am trying to make the show button bring back the h1 tag but it stops after reaching opacity: 0.1 instead of continuing all the way to opacity: 1.
I have tried debugging on Firebug for hours but cannot seem to crack it. Please help.
<!DOCTYPE html>
<html>
<head>
<title>Flesh and Bone</title>
</head>
<body>
<h1>Flesh and Bone</h1>
<button id="fade">Fade</button>
<button id="show">Bring Back</button>
<h2>The Killers</h2>
<script>
var el = document.querySelector("h1");
var fade = document.getElementById("fade");
var show = document.getElementById("show");
var fader = function () {
el.style.opacity = 1;
var timer = setInterval(function (){
el.style.opacity -= 0.1;
if (el.style.opacity == 0) {
clearInterval(timer);
}
}, 40);
}
var shower = function () {
el.style.opacity = 0;
var timer = setInterval(function (){
el.style.opacity += 0.1;
if (el.style.opacity == 1) {
clearInterval(timer);
}
}, 40);
}
fade.onclick = fader;
show.onclick = shower;
</script>
</body>
</html>