<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>完美框架</title>
<style type="text/css">
body,ul{
margin: 0px;
padding: 0px;
}
ul,li{
list-style: none;
}
ul li{
width: 200px;
height: 100px;
background: yellow;
margin-bottom: 20px;
opacity: 0.3;
filter: alpha(opacity:30);
border: 2px solid red;
}
</style>
<script type="text/javascript">
window.onload=function(){
var aLi =document.getElementsByTagName('li');
for (var i = aLi.length - 1; i >= 0; i--) {
aLi[i].timer=null;
aLi[i].onmouseover=function(){
startMove(this,'width',400,function(){
startMove(this,'height',400);
});
}
aLi[i].onmouseout=function(){
startMove(this,'width',200,function(){
startMove(this,'height',200);
});
} }
}
//var timer=null;
function startMove(obj,attr,iTarget,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var icur=0;
if (attr=='opacity') {
// statement
icur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
icur=parseInt(getStyle(obj,attr));
}
var speed=(iTarget-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if (iTarget==icur) {
clearInterval(obj.timer);
if (fn) {
fn();
}
}else{
if (attr=='opacity') {
obj.style.filter='alpha(opacity:'+(icur+speed)+')';
obj.style[attr]=(icur+speed)/100;
}else{
obj.style[attr]=icur+speed+'px';
}
}
},30);
}
function getStyle(obj,attr){
if(obj.currentStyle){
//IE
return obj.currentStyle[attr];
}
else{
//firefox
return getComputedStyle(obj, false)[attr];
}
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>