Smooth Drop Down

Discussion in 'JavaScript' started by nevex, Jan 23, 2010.

  1. #1
    Hey, I'm new here and I'm not that good with javascript, but it would be really nice if someone could help me out here.

    Currently I'm using this script for my drop down, but the question is, is it possible to edit it, so if you open it, it will open smoothly? Here's the script:

    Thanks in advance.
     
    nevex, Jan 23, 2010 IP
  2. harrierdh

    harrierdh Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    harrierdh, Jan 25, 2010 IP
  3. nevex

    nevex Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well I guess this animation could work, quote from that page you sent.

    
    var ContentHeight = 200;
    var TimeToSlide = 250.0;
    
    var openAccordion = '';
    
    function runAccordion(index)
    {
      var nID = "Accordion" + index + "Content";
      if(openAccordion == nID)
        nID = '';
       
      setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
          + openAccordion + "','" + nID + "')", 33);
     
      openAccordion = nID;
    }
    
    Code (markup):
    function animate(lastTick, timeLeft, closingId, openingId)
    {  
      var curTick = new Date().getTime();
      var elapsedTicks = curTick - lastTick;
     
      var opening = (openingId == '') ? null : document.getElementById(openingId);
      var closing = (closingId == '') ? null : document.getElementById(closingId);
     
      if(timeLeft <= elapsedTicks)
      {
        if(opening != null)
          opening.style.height = ContentHeight + 'px';
       
        if(closing != null)
        {
          closing.style.display = 'none';
          closing.style.height = '0px';
        }
        return;
      }
     
      timeLeft -= elapsedTicks;
      var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);
    
      if(opening != null)
      {
        if(opening.style.display != 'block')
          opening.style.display = 'block';
        opening.style.height = (ContentHeight - newClosedHeight) + 'px';
      }
     
      if(closing != null)
        closing.style.height = newClosedHeight + 'px';
    
      setTimeout("animate(" + curTick + "," + timeLeft + ",'"
          + closingId + "','" + openingId + "')", 33);
    }
    Code (markup):
    But question is, how to implant it?
    Thanks in advance.
     
    Last edited: Jan 26, 2010
    nevex, Jan 26, 2010 IP
  4. harrierdh

    harrierdh Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm outta here for today. But do a view source on that web page and find out how they are creating the (probably) <ul><li> etc. And look to see where they are calling those scripts. I have never used this. I just thought is was pretty cool.
     
    harrierdh, Jan 26, 2010 IP