//animation 
var ani = function(){this.init.apply(this,arguments)} 
ani.prototype = { 
 _id:function(i){ 
 if(!i) return; 
 return typeof i != "string" && i.nodeType === 1 ? i : document.getElementById(i); 
 }, 
 init:function(e,s,callback){ 
 this.e = this._id(e); 
 this.setInit(s||{}); 
 var maxS = parseInt(this.s.maxVal),speed = maxS==0?Math.max(this.getSty(this.e,this.s.sty),1):maxS/5; 
 this.fun(speed,maxS,callback) 
 }, 
 formula:function(x){ 
 var f; 
 switch(this.s.effect){ 
 case 0: 
 f = "outQuad"; 
 break; 
 case 1: 
 f = "inQuad"; 
 break; 
 case 2: 
 f = "bounce"; 
 break; 
 default: 
 f = "easeInBack"; 
 } 
 this.tween ={ 
 outQuad:function(pos){return Math.pow(pos, 2)},//outQuad 
 inQuad:function(pos){return -(Math.pow((pos-1),2)-1)},//inQuad 
 bounce:function(pos){//bounce 
 if (pos < (1 / 2.75)) { 
 return (7.5625 * pos * pos); 
 } else if (pos < (2 / 2.75)) { 
 return (7.5625 * (pos -= (1.5 / 2.75)) * pos + .75); 
 } else if (pos < (2.5 / 2.75)) { 
 return (7.5625 * (pos -= (2.25 / 2.75)) * pos + .9375); 
 } else { 
 return (7.5625 * (pos -= (2.625 / 2.75)) * pos + .984375); 
 } 
 }, 
 easeInBack:function(pos){var s = 1.70158;return (pos) * pos * ((s + 1) * pos - s);} 
 }; 
 return this.tween[f](x); 
 }, 
 findAry:function(attr){ 
 var rg = ["width","height","top","bottom","left","right","margin","padding"]; 
 for(var z in rg){ 
 if(rg[z]==attr) return true; 
 } 
 return false; 
 }, 
 setInit:function(s){ 
 this.s = { 
 sty:"width", 
 curClass:"", 
 maxVal:0,//效果最大值 
 effect:1//执行效果 
 } 
 for(i in s) this.s[i] = s[i]; 
 }, 
 setSty:function(x){ 
 var attr = this.s.sty; 
 if(this.findAry(attr)){ 
 this.e.style[attr] = x + 'px'; 
 var isIE6 = navigator.appVersion.indexOf("MSIE 6")>-1; 
 isIE6&&attr=="top"&&(this.e.style[attr] = x + document.documentElement.scrollTop + 'px'); 
 }else if(attr=="opacity"){ 
 this.s.maxVal===1&&(this.e.style.display = "block"); 
 this.e.style.opacity = x; 
 this.e.style.filter = "alpha(opacity="+x*100+")"; 
 }else{ 
 this.e[this.s.sty] = x 
 } 
 }, 
 getSty:function(e,s){ 
 var val = e.currentStyle?e.currentStyle[s]:document.defaultView.getComputedStyle(e,null)[s]; 
 return parseInt(val)||0; 
 }, 
 fun:function(f,m,callback){ 
 var D = Date,t = new D,e,T = 500,_this = this; 
 return e = setInterval(function() { 
 var z = Math.min(1, (new D - t) / T), 
 c = _this.s.curClass, 
 curC = _this.e.className; 
 _this.setSty( + f + (m - f) * _this.formula(z)); 
 if (z == 1) { 
 if (callback && typeof callback == 'function') callback(); 
 _this.s.maxVal==0&&(_this.e.getAttribute("style"))&&(_this.e.style.display="none"); 
 if(c!=""&&curC.indexOf(c)<0)_this.e.className += c; 
 clearInterval(e); 
 } 
 },10); 
 } 
} 
这是这个js展示的第一个DEMO1:
[html] 
 代码如下:
 
 
购物车
 
 
 
 script> 
 
 (function(){ 
 //线上调用这个插件的时候直接调用animation.js这个是压缩了的 
 var D = document,carMod = D.getElementById("J_car_mod"),carBox = D.getElementById("J_car_box"),carControl=true; 
 //移入显示 
 carMod.onmouseover = function(even){ 
 var even = even || window.event,target = even.target || even.srcElement; 
 if(target.className=="car-menu"){ 
 !!carControl&&(carObj = new ani(carBox,{maxVal:1,sty:"opacity"},function(){carControl=false;})); 
 carObj = null; 
 } 
 //移出隐藏 
 this.onmouseout = function(even){ 
 var e = even || window.event, 
 reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; 
 while (reltg && reltg != this){reltg = reltg.parentNode;} 
 if(reltg != this){ 
 !carControl&&(carObj1 = new ani(carBox,{maxVal:0,sty:"opacity"},function(){carControl=true;})); 
 carObj1 = null; 
 } 
 } 
 } 
 })() 
 script> 
这个是基于前面的那个弹出层的demo版本的效果,这个效果必须复制前面的弹出层的js哦部分代码如下
[html]
 代码如下:
 
 
 
 X 
 弹出层内容 
 
  script> 
  script> 
  
 var D = document,m = D.getElementById("J_popup"),con = D.getElementById("J_popup_con"),cl = D.getElementById("J_colse"); 
 new Popup(m,con,cl,{addFun:function(){new ani("J_popup_con",{sty:"top",maxVal:"350",effect:2})},callBack:function(){con.style.display="block";new ani("J_popup_con",{sty:"top",maxVal:"0"})}}) 
  script>