<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<style type="text/css">
*{margin: 0;padding: 0;}
#box{width: 200px;
height: 200px;
background-color: blue;
opacity: 0.3;
margin-left: 50px;}
</style>
</head>
<body>
<div id = "box"></div>
<script type="text/javascript">
window.onload = function(){
var box1 = document.getElementById('box');
box1.onmouseover = function(){changeTo(1.0)};
box1.onmouseout = function(){changeTo(0.3)};
}
var timer = null,alpha = 0.3;
function changeTo(a){
clearInterval(timer);
var box1 = document.getElementById('box');
timer = setInterval(function(){
if (alpha < a ){
alpha += 0.1;
box1.style.opacity = alpha; }
else if(alpha > a){
alpha -= 0.1;
box1.style.opacity = alpha;
}
else {clearInterval(timer);}
},300)
}
</script>
</body>
</html>