慕桂英9545975
2016-05-10 14:24
应该宽变宽之后跳出a,可是一开始就跳出a了
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>任意属性值2</title> <style type="text/css"> body,div{ padding:0;margin:0;font:normal 12px "微软雅黑"} div{ width:200px; height:150px; background-color: gold; top:20px; left:20px; filter: alpha(opacity:30); opacity: 0.3; float:left; margin-left:20px } </style> <script type="text/javascript"> window.onload=function() { var box = document.getElementById("box"); box.alpha=30; box.timer=null; box.onmouseover = function(){startMove(this,'width',300,alert("a"))}; }; function startMove(obj,attr,target,fn){ clearInterval(obj.timer); obj.timer=setInterval( function(){ var icur=0; if(attr=='opacity'){ icur=Math.round(parseFloat(getStyle(obj,attr))*100) }else{ icur= parseInt(getStyle(obj,attr)); } var speed=(target-icur)/8; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(icur==target){ clearInterval(obj.timer); if(fn){ fn() } }else{ if(attr=='opacity'){ obj.style.filter='alpha(opacity:'+(icur+speed)+')'; obj.style.opacity=(icur+speed)/100 }else{ obj.style[attr]=icur+speed+'px' } } },30) } function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; }else{ return getComputedStyle(obj,false)[attr]; } } </script> </head> <body> <div id="box"></div> </body> </html>
alert要用function(){}包裹起来
你这个代码好奇怪,即不像JS的外部文件
如果是写框架,你还需要传参吧
JS动画效果
113925 学习 · 1443 问题
相似问题