JS动画效果代码2 时间:2020-05-12 人气:0 Untitled Document <script language="javascript" type="text/javascript"> function $(pId){ return document.getElementById(pId); } function JPos(){ } JPos.getAbsPos = function(pTarget){ var _x = 0; var _y = 0; while(pTarget.offsetParent){ _x += pTarget.offsetLeft; _y += pTarget.offsetTop; pTarget = pTarget.offsetParent; } _x += pTarget.offsetLeft; _y += pTarget.offsetTop; return {x:_x,y:_y}; } function JAniObj(){ this.obj = null; this.interval = null; this.orgPos = null; this.targetPos = null; this.orgSize = {w:50,y:50}; //初始长宽 this.targetSize = {w:100,y:100}; //目标长宽 this.step = {x:10,y:10}; //步长 x:x方向 y:y方向 this.alpha = {s:10,e:90,t:10}; //透明度,s初始,e结束,t步长 } function JAni(){ var self = this; var aniObjs = {}; this.popup = function(pDiv,pOrgSize,pTargetSize,pStep,pAlpha){ var aniObj = new JAniObj(); aniObjs[pDiv] = aniObj; with(aniObj){ obj = $(pDiv); orgPos = JPos.getAbsPos(obj); orgSize = pOrgSize; targetSize = pTargetSize; step = pStep; alpha = pAlpha; with(obj.style){ overflow = "hidden"; position = "absolute"; width = pOrgSize.w + "px"; height = pOrgSize.h + "px"; left = orgPos.x + "px"; top = orgPos.y + "px"; if(document.all){ filter = "Alpha(opacity=" + pAlpha.s + ")"; }else opacity = pAlpha.s / 100; } } aniObj.interval = setInterval("popup_('" + pDiv + "')",10); } popup_ = function(pDivId){ pObj = aniObjs[pDivId]; var w = parseInt(pObj.obj.style.width); var h = parseInt(pObj.obj.style.height); if(w >= pObj.targetSize.w && h >= pObj.targetSize.h){ clearInterval(pObj.interval); if(document.all) pObj.obj.style.filter = "Alpha(opacity=" + pObj.alpha.e + ")"; else pObj.obj.style.opacity = pObj.alpha.e / 100; delete aniObjs[pObj.obj.id]; }else{ if(w < pObj.targetSize.w) w += pObj.step.x; if(h [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容