home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 October / Chip_2002-10_cd1.bin / internet / airforce / animate.js next >
Text File  |  2002-08-18  |  6KB  |  170 lines

  1. dynamicanimAttr="dynamicanimation"
  2. animCancel="skipanim"
  3. fpanimationPrefix="fpAnim"
  4. animateElements=new Array()
  5. currentElement=0
  6. speed=1
  7. stepsZoom=8
  8. stepsWord=8
  9. stepsFly=17
  10. stepsSpiral=16
  11. stepsSpiralWord=19
  12. stepsElastic=32
  13. steps=stepsZoom
  14. step=0
  15. cornerPhase=0
  16. outEffect=0
  17. function remSuffix(str){ind=str.indexOf("FP");str=str.substring(0,ind);return str}
  18.  
  19. function dynAnimOut(el){outEffect=1;dynAnimation(el);outEffect=0}
  20.  
  21. function dynAnimation(obj){animateElements=new Array()
  22. var ms=navigator.appVersion.indexOf("MSIE")
  23. ie4=(ms>0) && (parseInt(navigator.appVersion.substring(ms+5,ms+6))>=4)
  24. if(!ie4){if((navigator.appName=="Netscape") &&
  25. (parseInt(navigator.appVersion.substring(0,1))>=4))
  26. doc_els=document.layers
  27. else    return}
  28. else    doc_els=document.all
  29. if(outEffect && !ie4)return
  30. if(ie4){for (index=document.all.length-1; index>=document.body.sourceIndex; index--)
  31. {el=document.all[index]
  32. if(outEffect && el !=obj)continue
  33. if(outEffect)animationId=el.id.substring(9,el.id.length)
  34. else    animationId=el.id.substring(6,el.id.length)
  35. animation=remSuffix(animationId)
  36. if(null !=animation){altcnt=0
  37. if(    animation=="dropWord"    || animation=="flyTopRightWord"|| animation=="flyBottomRightWord"    || animation=="waveWords"|| animation=="hopWords")
  38. {ih=el.innerHTML
  39. outString=""
  40. i1=0
  41. iend=ih.length
  42. while(true){i2=startWord(ih,i1)
  43. if(i2==-1)
  44. i2=iend
  45. outWord(ih,i1,i2,false,"",outEffect ? obj.id : el.id)
  46. if(i2==iend)break
  47. i1=i2
  48. i2=endWord(ih,i1)
  49. if(i2==-1)i2=iend
  50. if (animation=="waveWords")
  51. outWordAlt(ih,i1,i2,true,animation,altcnt)
  52. else    outWord(ih,i1,i2,true,(outEffect ? "Out" : "")+animation,
  53. outEffect ?  obj.id : el.id)
  54. if(i2==iend)break
  55. i1=i2
  56. altcnt++}
  57. document.all[index].innerHTML=outString
  58. document.all[index].style.posLeft=0
  59. document.all[index].setAttribute(animCancel,true)
  60. document.all[index].style.visibility="visible"}}}}
  61. i=0
  62. for (index=0; index< doc_els.length; index++){el=doc_els[index]
  63. if(0 !=el.id.indexOf(fpanimationPrefix))continue
  64. if (ie4){elprops=el.style
  65. scrollOffsetTop=document.body.scrollTop
  66. docHeight=document.body.offsetHeight
  67. docWidth=document.body.offsetWidth
  68. elW=100
  69. elH=el.offsetHeight}
  70. else {elprops=el
  71. scrollOffsetTop=window.pageYOffset
  72. docHeight=window.innerHeight
  73. docWidth=window.innerWidth
  74. elW=el.clip.width
  75. elH=el.clip.height}
  76. if(outEffect)animationId=el.id.substring(9,el.id.length)
  77. else    animationId=el.id.substring(6,el.id.length)
  78. animation=remSuffix(animationId)
  79. if(outEffect && (obj !=el)){
  80. if(el.SRCID !=obj.id)continue}
  81. if (null !=animation ){
  82. if(ie4 && null!=el.getAttribute(animCancel,false))continue
  83. if(!ie4){elprops.posLeft=elprops.left
  84. elprops.posTop=elprops.top}
  85. el.startL=offsetLeft(el)
  86. if(animation=="flyRight" || animation=="elasticRight"){
  87. elprops.posLeft=-offsetLeft(el)+docWidth
  88. elprops.posTop=0}
  89. else if((animation.indexOf("waveWords") !=-1) || animation=="hopWords"){
  90. if(i){prevEl=animateElements[i-1]
  91. elprops.r=offsetLeft(el)-prevEl.startL}}
  92. else if(animation=="wipeLR" || animation=="wipeMID"){
  93. if (ie4 && elprops.position=="absolute"){el.sizeW=el.offsetWidth
  94. elprops.clip="rect(0 0 0 0)"}
  95. else if (!ie4){el.sizeW=el.clip.width
  96. el.clip.width=0}}else{continue}
  97. if(!outEffect){el.initLeft=elprops.posLeft
  98. el.initTop=elprops.posTop
  99. el.endLeft=0
  100. el.endTop =0
  101. elprops.visibility="hidden"}
  102. else{el.initLeft=0
  103. el.initTop=0
  104. el.endLeft=elprops.posLeft
  105. el.endTop=elprops.posTop
  106. elprops.posTop=0
  107. elprops.posLeft=0}
  108. if(!ie4){elprops.left=elprops.initLeft
  109. elprops.top=elprops.initTop}
  110. animateElements[i++]=el}}
  111. if(animateElements.length> 0){
  112. if(outEffect)    window.setTimeout("animate(1);",speed,"Javascript")
  113. else    window.setTimeout("animate(0);",speed,"Javascript")}}
  114. function offsetLeft(el){if(ie4){x=el.offsetLeft
  115. for (e=el.offsetParent; e; e=e.offsetParent)
  116. x+=e.offsetLeft
  117. return x}
  118. else{x=el.pageX
  119. return x}}
  120.  
  121. function animate(animOut){el=animateElements[currentElement]
  122. if(animOut)animationId=el.id.substring(9,el.id.length);
  123. else animationId=el.id.substring(6,el.id.length);animation=remSuffix(animationId)
  124. if (ie4)elprops=el.style
  125. else elprops=el
  126. if(!step && !animOut)elprops.visibility="visible"
  127. step++
  128. if(animation=="spiral"){steps=stepsSpiral
  129. v=step/steps
  130. rf=1.0-v
  131. t=v * 2.0*Math.PI
  132. rx=Math.max(Math.abs(el.initLeft),200)
  133. ry=Math.max(Math.abs(el.initTop),200)
  134. elprops.posLeft=Math.ceil(-rf*Math.cos(t)*rx)
  135. elprops.posTop=Math.ceil(-rf*Math.sin(t)*ry)}
  136.  
  137. else if(animation=="elasticRight"){steps=stepsElastic
  138. v=step/steps
  139. rf=Math.exp(-v*7)
  140. t=v * 1.5*Math.PI
  141. rx=Math.abs(el.initLeft)
  142. elprops.posLeft=rf*Math.cos(t)*rx
  143. elprops.posTop=0}
  144. else if(animation=="wipeLR"){steps=stepsElastic
  145. if(ie4 && elprops.position=="absolute")elprops.clip="rect(0 "+step/steps*100+"% 100% 0)"
  146. else if (!ie4){elprops.clip.right=step/steps*el.sizeW}}
  147. else if(animation=="wipeMID"){steps=stepsElastic
  148. if(ie4 && elprops.position=="absolute"){elprops.clip="rect(0 "+el.sizeW/2*(1+step/steps)+"px 100% "+el.sizeW/2*(1-step/steps)+")"}
  149. else if(!ie4){elprops.clip.right=el.sizeW/2*(1+step/steps)
  150. elprops.clip.left=el.sizeW/2*(1-step/steps)}}
  151. else{steps=stepsFly
  152. if(animation=="dropWord" || animation=="flyTopRightWord" || animation=="flyBottomRightWord")steps=stepsWord
  153. dl=(el.endLeft-el.initLeft) / steps
  154. dt=(el.endTop-el.initTop)  / steps
  155. elprops.posLeft=elprops.posLeft+dl
  156. elprops.posTop=elprops.posTop+dt}
  157. if (step>=steps){
  158. if(!(animation=="wipeLR"    || animation=="wipeTB"    || animation=="wipeMID"    || (animation=="flyCorner" && !cornerPhase))){elprops.posLeft=el.endLeft
  159. elprops.posTop=el.endTop}
  160. if(animOut){elprops.visibility="hidden"}step=0
  161. if(animation=="flyCorner" && !cornerPhase)cornerPhase=1
  162. else{cornerPhase=0
  163. currentElement++}}
  164. if(!ie4){elprops.left=elprops.posLeft
  165. elprops.top=elprops.posTop}
  166. if(currentElement< animateElements.length){
  167. if(animOut)window.setTimeout("animate(1);",speed,"Javascript")
  168. else    window.setTimeout("animate(0);",speed,"Javascript")}
  169. else currentElement=0}
  170.