为什么没有用?哪里写错了?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{
margin:0;
padding:0;
}
#box{
width:300px;}
#box li{
list-style:none;
width:200px;
height:100px;
background:#06F;
float:left;
margin:10px;
opacity:0.4;
filter:alpha(opacity=40);
}
</style>
</head>
<body>
<div id="box">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<script type="text/javascript">
window.onload = function(){
var lis = document.getElementsByTagName('li');
for(var i=0;i<lis.length;i++){
lis[i].onmouseover = function(){
startMove(this,{width:100});
}
}
var getStyle = function(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}
var startMove = function(obj,json,fn){
var flag = true;
clearInterval(obj.timer);
obj.timer = setInterval(function(){
for(var attr in json){
var icur = 0;
if(attr = 'opacity'){
icur = Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
icur = parseInt(getStyle(obj,attr));
}
var speed = (json[attr]-icur)/8;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(icur != json[attr]){
flag = false;
}
if(attr == 'opacity'){
obj.style.opacity = (icur+speed)/100;
obj.style.filter = "alpha(opacity:+'(icur+speed)')";
}
else{
obj.style[attr]=icur+speed+'px';
}
}
if(flag){
clearInterval(obj.timer);
if(fn){
fn();
}
}
},30);
}
}
</script>
</body>
</html>