Skip to content

Instantly share code, notes, and snippets.

@powerc9000
Created May 13, 2014 23:57
Show Gist options
  • Save powerc9000/6e3e3383e2ba3003321c to your computer and use it in GitHub Desktop.
Save powerc9000/6e3e3383e2ba3003321c to your computer and use it in GitHub Desktop.
Learning!
<html>
<head>
<title>Some page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p id="hello" class="hi">Hello World</p>
<div class="hi hide-contain">Hey!
<div class="hide hi">
something
</div>
</div>
<script src="script.js"></script>
</body>
</html>
var parent = document.getElementsByClassName("hide-contain")[0];
var child = parent.children[0];
var cancel;
var mouseout;
parent.addEventListener("mouseover", function(e){
var opacity = 0;
clearInterval(mouseout);
child.classList.add("over");
child.style.opacity = 0;
cancel = setInterval(function(){
child.style.opacity = opacity;
opacity += 0.1;
if(opacity >= 1){
clearInterval(cancel);
}
}, 20);
return;
});
parent.addEventListener("mouseout", function(e){
clearInterval(cancel);
var opacity = child.style.opacity;
mouseout = setInterval(function(){
opacity -=0.1;
child.style.opacity = opacity;
if(opacity <= 0){
child.classList.remove("over");
clearInterval(mouseout);
}
}, 20);
});
.hi{
color:red;
text-decoration:underline;
}
div{
width:100px;
border:1px black solid;
margin:auto;
padding:20px;
}
.hide{
display:none;
position:absolute;
top:0;
left:100px;
}
.hide.over{
display:block;
}
.hi:hover{
color:green;
}
.hide-contain{
position:relative;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment