同时运动问题
代码显示没有错误,就是运行不成功,求指教
js代码
function getStyle(obj,attr){
if(obj.currentStyle)
{
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}
function showMove(obj,json,fc){
clearInterval(obj.timer); //清除上一个计时器
obj.timer=setInterval(function(){
var flag=true;
for(var attr in json)
{
var getsome;
if(attr=="opacity")
{
getsome=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
getsome=parseInt(getStyle(obj,attr));
}
var speed;
if(getsome>json[attr])
{
speed=-2;
}
else{
speed=2;
}
if(getsome!=json[attr])
{
flag=false;
}
if(attr=="opacity")
{
obj.style.filter="alpha(opacity:'+(getsome+speed)+')";
obj.style.opacity=(getsome+speed)/100;
}
else{
obj.style[attr]=getsome+speed+"px";
}
if(flag)
{
clearInterval(obj.timer);
if(fc)
{
fc();
}
}
}
},30);
}
html页面调用代码
<script language="javascript" src="speed9.js"></script>
<script language="javascript">
window.onload=function(){
var allDiv=document.getElementById("d1");
window.onload=function(){
allDiv.onmouseover=function(){
showMove(allDiv,{width:300,height:120,opacity:100});
}
allDiv.onmouseout=function(){
showMove(allDiv,{width:150,height:60,opacity:30});
}
}
}
</script>