js闭包实现颜色渐变
<!doctype>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
#fade {
width: 50px;
height: 50px;
background: #ff11;
}
</style>
<script type="text/javascript">
window.onload = function(){
var node = document.getElementById('fade');
fade(node);
}
function fade(node){
var col = "#ff11", level = 1;
var fading = function(){
var hex = level.toString(16);
node.style.backgroundColor = col + hex + hex;
level++;
if (level < 16) {
setTimeout(fading, 100);
}
};
setTimeout(fading, 100);
}
</script>
</head>
<body>
<div id="fade">
</div>
</body>
</html>