Advertisement
Guest User

accordian.js

a guest
Nov 14th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ContentHeight = 200;
  2. var TimeToSlide = 250.0;
  3.  
  4. var openAccordion = '';
  5.  
  6. function runAccordion(index)
  7. {
  8.   var nID = "Accordion" + index + "Content";
  9.   if(openAccordion == nID)
  10.     nID = '';
  11.    
  12.   setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
  13.       + openAccordion + "','" + nID + "')", 33);
  14.  
  15.   openAccordion = nID;
  16. }
  17.  
  18. function animate(lastTick, timeLeft, closingId, openingId)
  19. {  
  20.   var curTick = new Date().getTime();
  21.   var elapsedTicks = curTick - lastTick;
  22.  
  23.   var opening = (openingId == '') ? null : document.getElementById(openingId);
  24.   var closing = (closingId == '') ? null : document.getElementById(closingId);
  25.  
  26.   if(timeLeft <= elapsedTicks)
  27.   {
  28.     if(opening != null)
  29.       opening.style.height = ContentHeight + 'px';
  30.    
  31.     if(closing != null)
  32.     {
  33.       closing.style.display = 'none';
  34.       closing.style.height = '0px';
  35.     }
  36.     return;
  37.   }
  38.  
  39.   timeLeft -= elapsedTicks;
  40.   var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);
  41.  
  42.   if(opening != null)
  43.   {
  44.     if(opening.style.display != 'block')
  45.       opening.style.display = 'block';
  46.     opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  47.   }
  48.  
  49.   if(closing != null)
  50.     closing.style.height = newClosedHeight + 'px';
  51.  
  52.   setTimeout("animate(" + curTick + "," + timeLeft + ",'"
  53.       + closingId + "','" + openingId + "')", 33);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement