<!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>test</title> </head> <body> <div id="abc" style="background-color:red; width:400px; height:300px;"></div> <div id="def" style="background-color:black; width:400px; height:300px;"></div> <script> function Fade(type,delay,callback){ var it=delay || 10 ,time,a=0,b=100,that=this; function set(i){ this.style.filter ="alpha(opacity=" + i + ")"; this.style.opacity= i/100; } function clear(){ clearInterval(time); if(callback){ callback.call(this); } } ({ 'in':function(){ set.call(that,0); time=setInterval(function(){ a++; if(a<=100){ set.call(that,a); }else{ clear.call(that); } },delay) }, 'out':function(){ set.call(that,100); time=setInterval(function(){ --b if(b>=0){ set.call(that,b); }else{ clear.call(that); } },delay) } }[type])(); arguments.callee.init=function(a){ set.call(this,a); } } var d=document.getElementById('abc'); var e=document.getElementById('def'); Fade.call(d,'out',10,function(){ Fade.call(d,'in',15,function(){ Fade.call(d,'out',10,function(){ Fade.call(d,'in',15,function(){ Fade.call(e,'in',15,function(){ setTimeout(function(){ alert('end'); },500); }); }); }); }); }); Fade.init.call(e,0); </script> </body> </html>
详细解决方案
写个fade练上手
热度:122 发布时间:2012-10-16 09:57:37.0
相关解决方案