NEWS: Alprazolam Debt consolidation lending Bad credit instant approval cards Debt consolidation Health insurance individual Debt consolidation help Life insurance broker Free instant online credit report Credit score uk Credit cards with low apr Paxil Transunion credit reports Credit report .com Buying life insurance Federal credit reporting act Application card chase check credit status. Bad credit instant approval cards Poor credit scores Free online credit report no trial offer Card collection credit debt law Used auto loans Cell Phone Ringtones Application card citibank credit Credit report fico score Cialis Credit cards instant approval Credit card applications for bad credit Scores credit: Refinance calculator VPN client Lorazepam Soma? Loan debt consolidation How do i get a free credit report Free debt settlement Best credit score Fixed apr credit cards Credit score interest Credit union annual meeting reports Bontril No credit checks instant aproval credit cards Student credit cards with no apr Plavix 0 apr balance transfer over 70 credit cards? Credit score repair Renova Credit cards instant approval Free Cingular Ringtones! Dianabol Credit report with score All three credit reports Credit score definition Child life insurance Score credit Singulair Credit card application status Card consumer credit debt stastics Virgin credit card application Diflucan Set up a VPN, Card consolidation credit debt financial internet Application card credit instant online No credit score mortgage Anonymous internet Zoloft Burial insurance Credit rating scores Nokia Ringtones Credit credit card applications Corporate credit card application Credit score definition Movian VPN VPN setup xp Refinance homes? Prozac Annuity insurance Valium Three credit scores Butalbital High credit score: Jc penny credit card application Whats my credit score! Child health insurance Credit card applications for people Stop credit card applications Good credit scores Credit report and scores A credit report First time home loans Credit scores explained Home insurance Popular press article on college credit card debt. Open VPN Real estate investing information free credit report score, Best credit score Credit card applications for people Instant payday loans Debt reduction solution credit card Open VPN Best credit report Debt consolidation service Lipitor! Business credit card online application No credit score Refinance auto loan Fair credit reporting act fcra Glucophage Poor credit score Advance payday loan Raising credit score: Free instant credit report online Fixed apr credit cards Credit cards with low apr Instant credit score Lowest apr rates on credit cards 025 apr balance transfer credit cards: Allegra Credit bureau scores Glucophage Instant approval on credit cards Free online credit report no trial offer Verizon Ringtones Debt settlement Secured credit card applications Best home equity loan A qualified mortgage consultant can help boost credit scores Fioricet Credit reporting law How to improve credit scores Credit report and scores Credit report .com Low interest apr credit cards, Uk online credit card application Credit score car loan! Free Sprint Ringtones No credit checks instant aproval credit cards Effexor Washington mutual credit card application. Payday loan Tramadol Capital one credit card application in canada Free online credit report no trial offer Card credit debt forgiveness settlement Effexor Credit cards instant approval and access Automobile title loans, Credit card application instant approval Bad credit instant approval cards Anonymous internet Card credit debt pay? Chevron credit card application Retin VPN tunnel Low fixed apr cards for low credit? Child life insurance Vantage credit score Free credit report com Payday loan? Bank credit card application Firewall and VPN Application bad card credit credit unsecured Credit card applications with Commercial loan Naprosyn Hotlink Caller Ringtones Application card credit online secured Health insurance No cost refinance Credit score of Secured home equity loans! Phentermine Stop credit card application mailers Zyban Credit score definition, Low interest credit cards visa fixed apr Interpreting credit scores Debt reduction solution credit card Anonymous surfing Health care insurance Credit card application bad credit Lortab Deceased credit card debt? Acyclovir Credit cards 1.99 apr ny Zithromax Levitra Diflucan Raising credit score Student loan bankruptcy Home insurance Credit card application form Victoria secret credit card application Propecia Good credit scores Secured credit cards low apr credit card balance transfer Zocor Debt consolidation versus credit card payment Credit cards mwith low apr Card credit debt plan reduction Credit score reports Fosamax Free credit score check? Best platinum credit cards with low apr Card con consolidate credit debt Military payday loan Home loan mortgage rates com refinance Credit score mortgage Lil Flip Ringtones 50 Cent Free Ringtones Fixed apr credit cards Information on credit report Fixed rate home equity loan. Credit scores online Celebrex Credit score interest rate Commercial property loan Equity home loans Low cost payday loan! Life insurance agencies Automobile title loans Consolidate student loan debt Card consolidation credit debt financial internet Credit card application with instant decision Small commercial loan Free VPN client Your credit report Raising credit score Home refinance loans Maxis Caller Ringtones Contivity VPN! Equifax free copy of credit report Alltel Ringtones Darude Ringtones 3 bureau online credit report Information on credit report Xanax New home loans Credit cards instant approval access Debt consolidation help To raise my credit score O apr credit cards Lorazepam. Credit card application high credit line immediate approval Credit scores mortgage. Instant approval student credit cards Credit score uk Increasing credit scores Allstate cancer insurance Renter insurance usa Online student credit card application Low interest apr credit cards Fosamax Hsbc credit card application and verification fraud Zoloft? Credit card applications for 0 credit card application My credit scores Instant online approval for credit cards Virtual private network Debt settlement companies. Relient K Ringtones Fix my credit report Stop credit card application mailers Credit card application high credit line immediate approval Interest rate credit score Credit card debt management credit card debt counseling Household bank credit card application Auto insurance companies. Motrin Credit card application with instant approval: No credit card application Best life insurance quote Motorola Ringtones Free instant credit report with no credit card? Debt settlement Real estate investing information free credit report score Ativan Zyrtec Nolvadex Credit card application instant approval. Card credit debt negotiation settlement Interpreting credit scores! Annual credit report free Debt consolidation with bad credit Cialis Glucophage Poor credit score Corporate credit card application College students average credit card debt Commonwealth bank credit card application. Free credit score check Online capital one zero interest credit card application Buy health insurance Debt consolidation service Credit card applications for bad Instant approval bad credit unsecured credit cards Kiss Ringtones Soma! Cialis Carisoprodol? Ringtones Cipro Chevron credit card application Application bad card credit credit unsecured: New credit score Tina Turner Ringtones Free Verizon Ringtones Credit card debt management credit card debt counseling Application card credit instant response Instant online approval for credit cards Online capital one 0 interest credit card application Card credit debt negotiation settlement Credit score simulator VPN tunnel Verizon Wireless Ringtones Mp Ringtones Instant approval credit cards in uk Meaning of credit scores. Didrex Guaranteed instant approval credit cards Us credit cards interest low apr 0 Secured credit card applications Lil Wayne Ringtones 50 Cent Free Ringtones Soma Compare auto insurance quote Cheap credit reports Eminem Ringtones Debt consolidation for credit card and vehicle loan ics Credit score rankings, Inderal Score credit Home mortgage credit card debt loan Exxon credit card application Free credit report georgia My credit scores Imovane Low interest apr credit cards Madonna Ringtones Low apr interest credit cards Low credit score loans Card credit debt eliminate now Scores credit Credit score uk Anualcreditreport.com Hsbc credit card application and verification fraud Adderall Household bank credit card application Instant approval low apr credit cards Low apr student credit cards Commercial equity loans Stop credit card applications. Enable VPN Debt consolidation help Providian credit card application 635 credit score My annual credit report Increasing credit scores Free access to credit reports Credit report dispute forms Download Free Ringtones Credit score codes Alltel Ringtones Credit reports canada Warranty auto Acyclovir My credit scores Fair credit reporting act of 1970, Instant approval student credit cards VPN server? Personal health insurance Instant approval credit cards for people with bad credit Card credit debt option reduction Credit card application for Instant approval bad credit unsecured credit cards Interest rate credit score, Credit report fico score A credit report Instant approval bad credit cards Free credit report online no membership Transunion credit reports Cibc credit card application Propecia Credit card debt consolidation information: Credit scores meaning Credit cards 1.99 apr ny Card consumer credit debt right Commercial loan! 0 apr credit cards uk 2004 card college credit debt mae nellie statistics student Zovirax Low fixed apr credit cards Bank credit card application Low apr credit cards Insurance home Card credit debt grant help pay Interpreting credit scores Insurance home? Equity home loans Card credit debt elimination scam Instant approval credit cards for people with bad credit Hotlink Caller Ringtones Diazepam Payday loan personal: Free business credit report Codeine! Guaranteed instant approval credit cards with no credit Famvir? Zoloft Clear credit report Trans union free credit report Polyphonic Ringtones? Credit card application forms Credit report with score Low interest credit cards instant approval Renova Free Mp Ringtones Credit report dispute form! Secured credit card application Bad consolidation credit debt help Personal credit reports Home equity VPN tunneling Health care insurance. American debt consolidation Buy health insurance Low cost payday loan Mac os x VPN! Credit card applications in Credit card application bad! Freecreditreports Consolidate loan student Low interest credit cards instant approval Three credit reports 3 bureau online credit report Free Nextel Ringtones Insurance credit score Automobile refinance? To raise my credit score Credit cards with low apr 635 credit score Eminem Ringtones Set up a VPN Dianabol Order credit report Credit card applications with Cialis Contivity VPN Client VPN Personal credit reports Credit score codes Card collection credit debt law 635 credit score Low credit score loans First time home loans Adderall Credit card offer Nortel VPN Federal law one free credit report yearly Credit cards with 0 apr! College students average credit card debt Warranty auto: Three credit reporting agencies Auto insurance: Time limit for reporting bad credit Instant approval canadian credit cards Card credit debt eliminate heritage 0 intro apr credit cards Free credit card application center Best creditcard debt reduction strategies Ringtones Copy of my credit report Unsecured credit cards low apr interest annual fee Buying life insurance Renova Instant credit card approval applications Codeine Credit reports for landlords, Remove credit card debt Secured loans to increase credit score Ambien Credit report uk Debt consolidation firm Popular press article on college credit card debt: Three credit reporting agencies Health care insurance Diflucan Canada credit card application Automobile refinance Three in one credit report Victoria secret credit card application Darude Ringtones Transunion free credit report Us credit cards interest low apr 0 Best card credit debt help vermont Free access to credit reports Commercial equity loans Motorola Ringtones Credit scores explained Credit card applications for bad Instant capital one 0 interest credit card application Tramadol? 0 apr on balance transfer credit cards Free VPN client Renter insurance usa Score credit International health insurance Increasing credit scores Commonwealth bank credit card application Canada credit card online application, Insurance life Fica credit score Propecia Retin Free credit report no membership No apr annual fee low interest credit cards Instant approval cards Instant approval credit cards for bad credit Gas credit card application Major credit reporting Prozac Cialis. Payday loan Low cost health insurance Obtain a credit report Singulair? Refinance investments Credit score online Lipitor Refinance loan International health insurance Best credit card debt help Credit report with score Home auto insurance Vicodin Get my credit score? Kmart credit card application Celtic Frost Ringtones Consumer credit reporting National credit reporting Life insurance Credit card application for people with bad credit. Low apr student credit cards Butterfly Ringtones VPN tunnel Zyrtec Auto loan New credit score Insurance credit score Target credit card application! Credit report dispute forms Credit report fico scores Credit report Zovirax, Nonprofit debt consolidation Low credit score loans Secured loans to increase credit score Phentermine How to read credit scores Cicsco VPN Credit score reports Debt consolidation for credit card and vehicle loan ics VPN tunneling Card consolidation credit debt: Norco Maxis Caller Ringtones Soma Cingular Ringtones: Nortel VPN Free Cingular Ringtones Credit free improve score Master card credit application Best card credit debt get way Home equity Ativan Refinance house Atarax Student loan bankruptcy? No credit score mortgage Life insurance Credit card applications in Household bank credit card application Transunion credit reporting Report free credit card required instant online. Imovane Prozac, Business credit card online application Credit bureau scores Card credit debt plan reduction Chevron credit card application Credit cards us instant approval Major credit reporting Credit reporting agencies addresses Refinance home Credit card debt counseling services Free credit report gov Credit reporting service Lo apr credit cards Nextel Ringtones Set up a VPN Negotiating settlement credit card debt Renter insurance quote Credit report fico scores Configuration VPN Best card credit debt help vermont Lowest apr rates on credit cards Application card credit interest low Find out my credit score Chase credit card application status Refinance home Risperdal Trans union free credit report Life insurance policies Didrex Average credit card debt in america Netgear VPN Apr for credit cards Equity home loans: Instant approval credit cards applications Wellbutrin Credit card applications for bad credit Dance Last Ringtones: Credit card applications for people Credit cards with low apr Effexor O apr credit cards. Augmentin Payday loan business Mortgage life insurance Fair credit reporting act fcra Is 700 a good credit score Torrente Visa credit cards apr Cosigning credit card applications! Secured home equity loans Trw credit reports? Credit score interest rate Credit card applications for bad Instant approval online credit cards 0 intro apr credit cards Instant approval online credit cards Credit score simulator Unsecured credit card application Low apr credit cards Improving credit scores Commercial property loan Ipsec VPN Credit card application status. Cibc credit card application How do i get my free annual credit report: Major credit reporting Paxil. Fix my credit score 800 credit card debt: Loan debt consolidation Credit card debt counseling services Instant approval credit cards bad credit Credit score online! 50 Cent Free Ringtones Chase credit cards 29.99 apr
  • 06
  • Mar


Well, my last tutorial post about creating a collapsible div (no animation) was a huge hit, receiving over 1100 diggs.

I actually learned quite a bit from the comments. First of all, I implemented the wp-cache 2.0 so my server doesn’t go down after 70-100 diggs again, haha. Secondly, I found people wanted animation… Digg comment style sliding. I can do that. :)

So, expanding on the last tutorial, I’ve coded a small Javascript library that will allow that functionality. It’s not meant to be a mootools or a script.aculo.us replacement… those are far more advanced libraries. This is just a simple, quick bit of code you can apply to your websites to improve the user experience a bit.

In this tutorial, we will create functions to slide DIVs up and down. It supports multiple animations happening simultaneously, as well as a variable animation length. It’s also time-based, rather than increment based, so it’ll animate the same speed on most computers; old computers won’t take 10 minutes for a DIV to slide down.

Click here to see the final product.

First, create a new file on your webserver called motionpack.js - this is where we will store all the javascript functions for the animations, rather than cluttering up the top of the webpage itself, and slowing down it’s load time. In the beginning of that file, let’s first declare some initial variables:
var timerlen = 5;
var slideAniLen = 500;
These are the variables you will change if you want to tweak the speed of the animation on your site. timerlen is how often the Javascript function will run to alter the DIV’s properties (altering height or opacity)… it’s probably best to leave this at 5. Any lower will be slightly smoother, but will require your visitors have a better computer (otherwise it’ll be choppy), and much higher will be choppy on everyone, because it’s not updating enough to look smooth. The next variable, slideAniLen, is how long it should take a DIV to completely slide up or completely slide down. This is in milliseconds, so setting it to 500 means it’ll take half a second to complete the animation effect. This is fairly quick, so some people might want to increase and make it a bit slower.

Now, the next part of the JS file:
var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();
These are some variables we’ll use throughout the code below to keep track of our animations. We use arrays for each object to allow multiple animations to happen simultaneously. We’ll explain where each of these are used later on, but for now, simply paste them into your JS file.

Now we’re getting to the actual functions. These first functions are what we call from our website itself. They essentially serve as the API for this mini-library.
function slidedown(objname){
  if(moving[objname])
    return;
 
  if(document.getElementById(objname).style.display != "none")
    return; // cannot slide down something that is already visible
 
  moving[objname] = true;
  dir[objname] = "down";
  startslide(objname);
}
 
function slideup(objname){
  if(moving[objname])
    return;
 
  if(document.getElementById(objname).style.display == "none")
    return; // cannot slide up something that is already hidden
 
  moving[objname] = true;
  dir[objname] = "up";
  startslide(objname);
}
This code adds the functions to call when requesting a DIV start sliding up or down. Let’s first look at the slideup() function. We pass it a single parameter- the DIV’s id (objname). The first line checks if the moving variable is set to true for that DIV, so we don’t begin animation on one that’s already moving. Once an animation starts, it will finish uninterrupted. If it is moving, on line 3, we return (exit from the function) so no further animation begins. The next line is a sanity checking if-statement. This function is beginning the slide down process of a DIV, and if a DIV’s display attribute is not set to none (not visible), we assume it’s already slid down and visible, so we can exit the function (abort the process), since there’s nothing else for us to do here. If those checks complete without any complications, we’re now ready to begin the sliding process, so we set the moving variable to true (so no other animation can start until we’re done), we set the direction variable to down (so it knows which way to move), and we call the function startslide(), which we’ll get to in a moment. The slideup() function is very similar, except it checks on the 3rd line inside that function to ensure the display property is not set to “none”, so the DIV is not visible, otherwise we have nothing to slide up, and we can abort the start slide process.

Now, I hope you guys are hanging in there, we’re almost through the tricky parts. :)

The next function we’ll throw in the file is the startslide() function mentioned above:
function startslide(objname){
  obj[objname] = document.getElementById(objname);
 
  endHeight[objname] = parseInt(obj[objname].style.height);
  startTime[objname] = (new Date()).getTime();
 
  if(dir[objname] == "down"){
    obj[objname].style.height = "1px";
  }
 
  obj[objname].style.display = "block";
 
  timerID[objname] = setInterval('slidetick('' + objname + '');',timerlen);
}
Okay, the last two functions were for making sure we really want to start the slide, and doing all the initial preparations. This function, startslide(), is where we actually begin the sliding process. We, as always, pass the DIV’s id (objname) that we’re working with as the function’s parameter. On the first line of this function, we set it in the obj[] array, so we can keep track of the id throughout the animation process. The next two lines set the endHeight to the original height (so we know where to start sliding from, or how far down to slide to), and the startTime, so we can keep track of how long this animation has been going on. Following this we have a nice three line if-statement that checks if we’re sliding down, and if we are, resizes the DIV’s height to 1px… a starting point to slide down from. Next it sets the object’s display attribute to “block”, making it visible (redundant if sliding up, but a good just-in-case measure never-the-less). Note: You might want to use “inline” instead of “block”, depending on your circumstances (inline will allow the DIV to have other content to the left and right of it, rather than adding a line break before and after it like block does), just be aware to change the other occurrences of “block” to “inline” if you do this. Finally the last line of the function is where we’ve set the initial timer, which will call the sliding function ever few milliseconds (depending on your settings of timerlen up top), and actually perform the animation itself.

Now, the function the above timer called was slidetick(), which is the next part of our motionpack.js file.
function slidetick(objname){
  var elapsed = (new Date()).getTime() - startTime[objname];
 
  if (elapsed > slideAniLen)
    endSlide(objname)
  else {
    var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
    if(dir[objname] == "up")
      d = endHeight[objname] - d;
 
    obj[objname].style.height = d + "px";
  }
 
  return;
}
This function is what actually does the animation itself. The first line checks how long the animation has been in progress, by subtracting the animation’s start time from the current time. There’s then an if-statement that checks if the animation has exceeded the preset time (at the top of this file) for an animation’s length, and if so, it calls the endSlide() function, which cleans up (discussed below). If the elapsed time is not greater than the max time (the else-statement), it calculates the variable “d”. This calculation takes the ratio of time that’s progressed so far in the animation, and multiplies it by the final height of the DIV, so if half the time has progressed, for example, the variable d will contain half the height. Then it checks the direction, and if we’re sliding up, it alters d to it’s inflection… sliding the opposite direction (three quarters the way through the time would either be three quarters the way down if sliding down, or a quarter of the way from the top, if sliding up). Next we set the DIV’s height to “d” using it’s CSS style.height property.

Now, the last function we’re needing in the motionpack.js file is the endSlide() function:
function endSlide(objname){
  clearInterval(timerID[objname]);
 
  if(dir[objname] == "up")
    obj[objname].style.display = "none";
 
  obj[objname].style.height = endHeight[objname] + "px";
 
  delete(moving[objname]);
  delete(timerID[objname]);
  delete(startTime[objname]);
  delete(endHeight[objname]);
  delete(obj[objname]);
  delete(dir[objname]);
 
  return;
}
This is the function that’s called when the time runs out on an animation. It finishes everything and cleans up. The first line kills the animation timer, so it doesn’t keep trying to slide. The if-statement checks, and if it was sliding up, it hides the DIV by changing it’s display attribute to “none”. It readjusts the DIV’s height to the original height, so future animations will work fine on it. Then finally there are all those delete lines, deleting any array element we created to keep track of the different animations throughout the process. This cleans up a bit to ensure there are no memory leaks (for sites with lots of animations), etc. After this function is completed, the animation process is done.

Now you can save that file, with all the pieces above saved up, and upload it to your webserver.

To download the entire above JS file, you can get it here.

Now, we have our entire mini-library done…. so how do we use it?

First we need to include it in our website. This is done by adding this quick line to your website on every page that you’re using the animation, preferably in the HEAD tag:
<script language="JavaScript" src="motionpack.js"></script> This code assumes the file you uploaded is named “motionpack.js” and is in the same folder as your website source code itself. Another common practice is to create a folder called js/ and put all your javascript include files there together, and in that case, you’d change the src tag above line to “js/motionpack.js”. Easy.

Now that page of your website has sliding abilities! But how do we use them?

First, let’s create a DIV, like we did with our last collapsible DIV tutorial:
<div id="mydiv" style="display:none; overflow:hidden; height:95px;"><h3>This is a test!<br>Can you see me?</h3></div> Notice we did make one change though. We added an “overflow: hidden” attribute and “height:95px” to the style property of the DIV. These property MUST be present on all DIVs you use for sliding. If you don’t include the overflow attribute, it’ll look very ugly, with text overlapping on other content and such. If you don’t include a static height here, it won’t know how far to slide, so it won’t work at all. Aside from that, it’s virtually the same. You can put whatever you want inside the div, just be sure to adjust the height accordingly.

The difference is this time our link calls functions from our library above. Here’s an example of what a Slide Down link might look like:
<a href="javascript:;" onmousedown="slidedown('mydiv');">Slide Down</a> Notice in the onmousedown function we call the slidedown() function from our above library. This will begin the animation and slide the DIV down, until it’s completely visible. You can replace slidedown() with slideup() to do just that, slide the DIV up.

As a challenge to you, try using what you’ve learned in this tutorial and the last to create a toggleSlide() function. It would be a simple if-statement to check if the link’s “display” property, and either slide it up or down, depending on it’s state. We did something very similar in the last tutorial, so try applying that here!

And finally, he’s a working example of it:

Slide Down   |   Slide Back Up

Hope this helps!

Edit: Due to a high number of requests, I’ve made a followup post explaining how to use this code in a one-click toggle situation: Toggle Sliding DIV :)

» You can leave a comment, or trackback from your own site.

894 Comments

  1. Kev Says:

    Thats some nice work.

  2. Dan Says:

    Cool work

  3. Scott Says:

    I can’t get your examples (Slide Up, Slide Down links) to work with FireFox, but it works with IE. Do you know why? Great Tutorial Though..

  4. ilanko Says:

    Nice one, it will be nice to wipe “mydiv” horizontal too

  5. Harry Says:

    Scott, what problem are you having in Firefox? I’m using Firefox 2.0 right now and the sliding seems to work fine.

    Regards,
    - Harry

  6. Harry Maugans » How to Create a Collapsible DIV with Javascript and CSS Says:

    […] Note, I’ve since made an updated post to this, with Digg comment style sliding animation included. Digg Article - Actual Link […]

  7. Brétema : Blog Archive : Cómo crear un DIV expandible con CSS y Javascript Says:

    […] opciones adicionales tras enlaces que al ser pulsados muestran su contenido. En la página de Harry Maugans nos encontramos con un script que nos permitirá realizar este efecto haciendo visible el contenido […]

  8. chet Says:

    great job

  9. DQ Says:

    How does display:none effect search engine optimization? Do search engines ignore content that is within a display:none div?

  10. Steve Says:

    awesome

  11. Ian Says:

    Really cool.

  12. Charles Says:

    You might want to use unique IDs, from your front page your earlier example of a hidden div activates and deactivates the div in this example.

  13. Dan Says:

    Thanks for sharing, I’ve been wanting to do something like this!

  14. Brombomb Says:

    Sweet. Thanks for the tip. I commented yesterday, but will definatly be adding this as well.

  15. Jim Says:

    Real nice that - well explained tutorial.

  16. State Of Brain Says:

    This is pretty neat. Thanks for taking the time to write it up!

  17. Juanjo Says:

    Nice work, thanks for the share

  18. tont Says:

    im not using firefox 1.5 and its not working. but, like the other guy, it works in IE.

  19. How to Create Digg Comment Style Sliding DIVs with Javascript and CSS « Tons of Fresh News Says:

    […] 6, 2007 at 7:32 pm · Filed under Uncategorized How to Create Digg Comment Style Sliding DIVs with Javascript and CSS A great step-by-step tutorial on how to create a sliding DIV like Digg uses for burying comments. […]

  20. John Says:

    Awesome!

  21. How to Create Digg Comment Style Sliding DIVs with Javascript and CSS Says:

    […] read more […]

  22. Drew Says:

    Have you done browser compatibility checks?

    Which browsers will this not work with, and does the information default to visible?

  23. JimmyLn Says:

    Wow this is so cool!

  24. Dan Esparza Says:

    Works fine for me in Firefox 2.0.0.2

  25. John Says:

    i am liking the comment system.

  26. Strzalek Says:

    It is cool

  27. animated sliding DIV with Ajax at trilodge computin blog Says:

    […] ich mich den ganzen Tag mit Ajax rumgeärgert habe, poste ich jetz zum Ausgleich ein Tutorial von Harry Maugans über, dank Ajax-scripts, animierte sich auf- und zu-klappende […]

  28. links for 2007-03-07 | On Influence and Automation Says:

    […] Harry Maugans » How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS I’ve coded a small Javascript library that will allow that functionality. It’s not meant to be a mootools or a script.aculo.us replacement… those are far more advanced libraries. (tags: css javascript webdesign div tutorial animation ui) […]

  29. thankful reader Says:

    Awesome! First js script tutorial I could understand! Thanks again for sharing.

  30. Jen Says:

    Awesome!

  31. Johnpowell Says:

    Thanks.. That is very cool.

  32. Like Your Work » Blog Archive » links for 2007-03-08 Says:

    […] Harry Maugans » How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS (tags: ajax) […]

  33. Schneider Says:

    Cool.
    Is there any way to use a dynamic height?

  34. Anthony Ettinger Says:

    I like the animation pattern, simple and effective. Could use some cross-browser comliancy, but the just of it is conveyed nicely.

  35. Anthony Ettinger Says:

    I like the animation pattern, simple and effective. Could use some cross-browser compliancy, but the just of it is conveyed nicely.

  36. undefined Says:

    I am getting objname is undefined error in the error console. Anyone else running into a problem.

  37. undefined Says:

    Fixed the error I had to add an extra escape character to line 257
    out.print.ln(”timerID[objname] = setInterval(’slidetick(” + objname + ”);’,timerlen);”)

    needed to be

    out.println(” timerID[objname] = setInterval(’slidetick(” + objname + ”);’,timerlen);”);

  38. Dean Ward Says:

    Great work it saved me a lot of headaches, Thanks!

    I have added a fade effect to it , it fades AND slides in and out now: The new code is below

    var timerlen = 5;
    var slideAniLen = 250;

    var timerID = new Array();
    var startTime = new Array();
    var obj = new Array();
    var endHeight = new Array();
    var moving = new Array();
    var dir = new Array();

    function slidedown(objname){
    if(moving[objname])
    return;

    if(document.getElementById(objname).style.display != “none”)
    return; // cannot slide down something that is already visible

    moving[objname] = true;
    dir[objname] = “down”;
    startslide(objname);
    }

    function slideup(objname){
    if(moving[objname])
    return;

    if(document.getElementById(objname).style.display == “none”)
    return; // cannot slide up something that is already hidden

    moving[objname] = true;
    dir[objname] = “up”;
    startslide(objname);
    }

    function startslide(objname){
    obj[objname] = document.getElementById(objname);

    endHeight[objname] = parseInt(obj[objname].style.height);
    startTime[objname] = (new Date()).getTime();

    if(dir[objname] == “down”){
    obj[objname].style.height = “1px”;
    }

    obj[objname].style.display = “block”;

    timerID[objname] = setInterval(’slidetick(” + objname + ”);’,timerlen);
    }

    function slidetick(objname){
    var elapsed = (new Date()).getTime() - startTime[objname];

    if (elapsed > slideAniLen)
    endSlide(objname)
    else {
    var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
    var f =elapsed / slideAniLen;
    if(dir[objname] == “up”){
    d = endHeight[objname] - d;
    f = 1 - f;}

    obj[objname].style.height = d + “px”;
    obj[objname].style.opacity = f;
    obj[objname].style.filter = ‘alpha(opacity=’+(f*100)+’)';
    document.getElementById(’searchtextbox’).value=f;

    }

    return;
    }

    function endSlide(objname){
    clearInterval(timerID[objname]);

    if(dir[objname] == “up”){
    obj[objname].style.display = “none”;
    obj[objname].style.opacity = 0;
    obj[objname].style.filter = ‘alpha(opacity=’+(0)+’)';
    }
    else{
    obj[objname].style.opacity = 1;
    obj[objname].style.filter = ”;
    }

    obj[objname].style.height = endHeight[objname] + “px”;

    delete(moving[objname]);
    delete(timerID[objname]);
    delete(startTime[objname]);
    delete(endHeight[objname]);
    delete(obj[objname]);
    delete(dir[objname]);

    return;
    }

    you also need to add some stuff to the div

    style=”display:none; overflow:hidden; height:9px;opacity:0.0;filter: alpha(opacity=0);”

  39. Cohenville » Blog Archive » Create a sliding DIV on your web page Says:

    […] such as script.aculo.us.  Firblitz posted a nice tutorial, which was initiated by an additional post from Harry […]

  40. Devlounge | Friday Focus #21 Says:

    […] - How to Create Sliding, Collapsible Div An article outlining the steps to create a sliding, collapsible div with javascript and css. […]

  41. Matthew Alan Cline. K2 styles, css and web design babblings. Says:

    […] read more | digg story […]

  42. bahodir Says:

    Awesome, it works on firefox too….

  43. Fatih Hayrioğlu’nun not defteri » 10 Mart 2007 Web’den seçme haberler Says:

    […] Javascript ve CSS ile hazırlanmış güzel bir geçiş efektli açılır menü örneği anlatımı ve kodu. Link […]

  44. Jason Neuman Says:

    I saw your review on John Chow’s site today and wanted to know if you would be interested in a review. Please visit my site for for review exchange rules, let me know if you are interested in a review exchange.

    http://jakeldaily.com/?p=42

    :ppled fpr your email but did not see it, so decided to leave this in a comment

  45. Dieter Says:

    Nice tutorial, only problem is the static height. Pain in the ass if you have dynamic content!

  46. hmaugans Says:

    @ Dieter,

    Do you know a way around that?

  47. dafin Says:

    havnt you guys heard of AJAX?

  48. Ajith Says:

    it works well but only only by specifying height of the div…..advice me…

  49. Max Design - standards based web design, development and training » Some links for light reading (14/3/07) Says:

    […] How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS […]

  50. Alexx Says:

    nice, it works here in any browser.

    thanx for sharing it,…

  51. Nate Klaiber Says:

    RE: dafin
    Apparently you are a little confused yourself. This has nothing to do with AJAX (At all). It is used in conjunction with AJAX, but AJAX doesn’t do the animation. AJAX is a middle layer of communication between the client/server.

    Now, prototype.js and scriptaculous do what you are speaking of, and are tied in with most RoR apps and AJAX apps - but they are not the same thing.

  52. Dieter Says:

    @hmaugans: No i don’t but if i find some spare time i’ll take a look at it.

  53. John Faulds Says:

    Another thing to keep in mind is that if the user has javascript disabled, they’ll never be able to access the hidden content because the display: none is in the HTML. Better to set both the div’s initial and toggle states via javascript so that if js is disabled, the element will still be visible.

  54. Ocira Says:

    Thanks for the tutorial. An easier implementation similar to the “Overlapping Content” script I used on this list -> http://www.mru.ug/index.php?option=weblinks&Itemid=60 Script from dynamic drive

  55. haris Says:

    is there a way to slide horizontally ? left or right ?

  56. Bornie Says:

    function slide(objname){
    if(moving[objname])
    return;
    if(document.getElementById(objname).style.display == “none”)
    slidedown(objname);
    else
    slideup(objname);

    }

    Use this function to have a single function for sliding up/down

  57. Chris Says:

    Why not just use jQuery?

    $(’#div’).fadeIn(speed).slideDown(speed);

    Easy!

  58. hmaugans Says:

    @Chris,

    Read the comments in the Digg article. jQuery would work, but the purpose of this is to be lightweight, lean, and a learning experience.

  59. How to Create Digg Comment Style Sliding DIVs with Javascript and CSS » Prateek Says:

    […] read more | digg story […]

  60. Webman Says:

    Great example, really slick!

    Just wondered about accessibility, does it work without a mouse?

  61. thinkabout Says:

    Nice tutorial!

  62. Regal Says:

    Very Nice, This might encourage me to learn more :)

  63. John Says:

    So how do you to the toggle slide then? maybe you should post a how to for that.

  64. Harry Maugans » Tutorial: AJAX Made Easy Says:

    […] the heels of two very successful tutorials on creating a collapsible div and an animated sliding div, I’ve decided to write another. It seems my last few helped a number of programmers learn a […]

  65. Bob Says:

    Coolio!

  66. tomtom Says:

    very cool

  67. chris Says:

    Good job

  68. Yansky Says:

    @ Dieter & hmaugans
    re: div height & dynamic content

    Specify no height for the div to begin with & a style rule of display:none in the stylesheet, then load the dynamic content into the div (since the div is hidden, nothing will show), you can then read the div’s height and assign it to a variable.

    e.g. something like this:
    var theDiv = document.getElementById(’myDiv’);
    var divHite = document.theDiv.scrollHeight;
    theDiv.style.height= divHite;

    Here’s a full jQuery example. (I know your intent was to show how to code it from start to finish with base javascript, I only provide this example because I recently used it on a site I was working on & hopefully it will convey my idea a bit better)

    #ajax-div is given a css rule of display:none; in the stylesheet.

    $(’.ajax-div-slide’).click(function() {
    $(’#ajax-div’).load(this.href, function() {
    var divHite = $(’#ajax-div’).height();
    $(’#ajax-div’).height(0).css(”display”, “block”);
    $(’#ajax-div’).animate({height: divHite},});
    });
    return false;
    });

  69. John Says:

    function slide(objname){
    if(moving[objname])
    return;
    if(document.getElementById(objname).style.display == “none”)
    slidedown(objname);
    else
    slideup(objname);

    }

    Where do i add that exactly and how do i call the function in a link? Could you explain please.

  70. How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS » Webdesign Archive Says:

    […] How to create functions to slide DIVs up and down. It supports multiple animations happening simultaneously, as well as a variable animation length. It’s also time-based, rather than increment based, so it’ll animate the same speed on most computers. [go] […]

  71. Scott Says:

    Harry,

    Sorry it took so long to respond. I wrote about 10 days ago that it wouldn’t work for me in Firefox. I wasn’t totally correct. It works for me on Firefox at home, but not at work? Both are versions 2.0.0.2. I don’t know, maybe its some setting I have… Any ideas. I’m glad I can finally see it now in Firefox!

    Scott

  72. alternapop Says:

    @john:

    just add that function to the motionpack.js file. change the function in the html to call slide().

    watch the quotes around “none” in the new function when copying and pasting.

  73. links for 2007-03-20 » Way Over Yonder in the Minor Key Says:

    […] How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS (tags: css design programming tutorial) […]

  74. John Says:

    @alternapop

    Thanks for your help. Works now. I dont have any knowledge of Javascript so this entire thing puzzled me, works now though and looks very snazzy.

  75. Harry Says:

    Congrats John, and thanks alternapop!

  76. Gordon Tatler Says:

    An easier way. Put this script in the page header

    function show_hide(the_layer)
    {
    if(document.getElementById(the_layer))
    {
    if(document.getElementById(the_layer).style.display == ‘none’)
    {
    document.getElementById(the_layer).style.display = ‘inline’;
    }
    else
    {
    document.getElementById(the_layer).style.display = ‘none’;
    }
    }
    }

    and then in the page body put the following

    Show/hide some text

    This is the Text to show/hide.

    The display:none will ensure that the text is hidden on page load.

    If you have more than one div you want to show/hide then call them (say) foobar1 and foobar2 etc.

    A working example is on my Agatha Christie web site. This has a list of the plots and solutions of all 66 of her full length novels. When viewing the plots the solution is hidden in a foobar div and can be shown/hidden by clicking the link. See it in action at http://www.gbtamc.co.uk/et/index.php?id=644

  77. Gordon Tatler Says:

    Sorry. Here is the page code.

    Show/hide some text

    This is the text to show/hide

  78. Gordon Tatler Says:

    The script

    function show_hide(the_layer)
    {
    if(document.getElementById(the_layer))
    {
    if(document.getElementById(the_layer).style.display == 'none')
    {
    document.getElementById(the_layer).style.display = 'inline';
    }
    else
    {
    document.getElementById(the_layer).style.display = 'none';
    }
    }
    }


    The page details

    Show/hide some text

    The text to show/hide

  79. Tony Says:

    Thank you for the tutorial. Good job. How would one toggle the show/hide to make it a + or - depending on the status of the divs visibility? Or say it was collapsed it would say “Show more… ” and if the div was visible it would instead say “Hide details”

  80. Stephen Clark Says:

    Similar to what Tony is asking, how can you configure it so there is only one link instead of two? Click the link once to expand and click it again to close..

  81. Adam Dempsey Says:

    Very useful, thanks :) Exactly what I’ve been looking for.

  82. Abaddon Says:

    Excelllent script man…
    Works both in IE and FF.
    thanx a lot… keep up the good work and write more scripts

  83. william Says:

    Awsome script, neat, short and easy to understand, not like other script that I have seen before looks very complicated. I am going to use it to hide and show login in form dynamically instead of reloading to another page.

  84. JoE Says:

    Anybody find a way to apply this to a single button? I messed around with it, but I’m not very DOM inclined. And from what I had, I thought it would change out the button once clicked, but it does not. I’d post up the code, but I don’t want to confuse anybody else who might read this later.

  85. Harry Maugans » One Click Toggle for Sliding, Animated DIV Says:

    […] gotten quite a few comments on my recent post about creating a sliding, collapsible DIV, and while I like to leave some things unsaid, to be figured out by the reader… one question […]

  86. Harry Says:

    Joe, and anyone else asking above. I just made a new post explaining how to do this with a single button (toggle):
    http://www.harrymaugans.com/2007/03/24/one-click-toggle-for-sliding-animated-div/

  87. Jeff Says:

    1. Is there any way to use this with a few windows, where opening one would close the others? I’ve gotten it to work on two, but more than two won’t (possibly because I can’t use a list for the slideup function?).

    2. Anyone know how to get this to degrade nicely for those who don’t have JavaScript enabled? I’ve seen it done:

    http://webassist.com/professional/community/webproresource/masters/client_survey.asp

    This one displays all of the divs if js is disabled, one at a time slides in if enabled…

    Thanks in advance…

  88. NIk Says:

    I need same thing but left to right , what I have to do and I also want that fading in.

    I can use alpha through css, but will that increase or decrease with java if yes then how?

  89. Lazy Hacker Babble » Blog Archive » Creating sliding DIVs Says:

    […] a sliding divs like you see on Digg or many other sites. It was written in response to another tutorial on implementing a similar […]

  90. Animated DIV’s Made Simple at Thoughts From the Train Station Says:

    […] entry by Harry Maugans is far and away one of the best examples of animated DIV tags that I’ve come […]

  91. Animated DIV’s Made Simple at Web ShopTALK Says:

    […] entry by Harry Maugans is far and away one of the best examples of animated DIV tags that I’ve come […]

  92. links for 2007-03-15 en newdisco Says:

    […] Harry Maugans » How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS Solo eso. (tags: css javascript ajax) […]

  93. boris Says:

    Harry,

    I can’t get the collapsible div to work on IE 6.0 — but it does work on Firefox?

    Any fix?

  94. Daniel Says:

    Hi there, firstly great little tutorial.

    One bug, it doesn’t take into account div padding. Padding changes the viewers perspective of the div’s height and therefore the script should add the padding to the height.

    Thanks, Daniel

  95. zombie Says:

    Hello Sir,

    Really fond of the information and the quality of information that you have left on your site. I am really obliged by your wish to help people.

    Regards,
    zombie

  96. Wouter Says:

    I guess browser compatibility is a large issue here. Here are the stats so far:

    Firefox 1.5: Doesnt work (see comment by tont)
    Firefox 2.0.0.3: Works (tested myself)
    Internet Explorer 6.0: Doesnt work (see comment by boris)
    Internet Explorer 7.0: Works (tested myself)

  97. Arron Says:

    Would love to get some more details about dynamic height(s) :

    As was mentioned :

    var theDiv = document.getElementById(’myDiv’);
    var divHite = document.theDiv.scrollHeight;
    theDiv.style.height= divHite;

    But not sure how to implement this…

  98. boris Says:

    Wouter,

    I was able to get it to work on IE 6.0 by changing around my core stylesheets. There is a good change it had nothing to do with Harry’s code.

  99. Jason Says:

    Harry,

    I’m trying to use your script but it’s just not quite working for me, I probably did something wrong but here’s where Im stuck at-

    under the

    My problem is that when the div is first toggled it slides the entire set height but then disappears almost instantly. When I click again, I get it slides down only to 1px. But when I set the

    obj[objname].style.height = “1px”;

    that is within the startslide() function to my specified height, it seems to work fine except for the fact that it jumps erratically when toggling down but the animation seems to be fine.

    I know I’m not supposed to set it beyond 1px to prevent the erratic jump but it was one of the only things I found to actually display my div!

    Do you have any idea what it might be?

  100. Leon Says:

    Great function, I’ve tried to make it a little neater on the vars it uses. I’ve made some big assumptions (ie. using .px but this regex can trim any dimension just change the regex?).

    var timers = new Array();

    function toggle(elementId){
    element = document.getElementById(elementId);
    if(element!=null&&timers[elementId]==null){
    if(element.style.height.replace(”px”,”")>1){
    timers[elementId] = setInterval(”shrink(’”+elementId+”‘)”,5);
    }else{
    timers[elementId] = setInterval(”grow(’”+elementId+”‘,400)”,5);
    }
    }
    }

    function shrink(elementId){
    element = document.getElementById(elementId);
    if(element!=null){
    if(element.style.height.replace(”px”,”")(height-10)){
    // clear timer
    clearInterval(timers[elementId]);
    element.style.height=height;
    timers[elementId]=null;
    }else{
    element.style.height = Math.min(element.style.height.replace(”px”,”")-(-5),height);
    }
    }else{
    clearInterval(timers[elementId]);
    }
    }

  101. Best of March 2007 | Smashing Magazine Says:

    […] How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS In this tutorial, we will create functions to slide DIVs up and down. It supports multiple animations happening simultaneously, as well as a variable animation length. It’s also time-based, rather than increment based, so it’ll animate the same speed on most computers; old computers won’t take 10 minutes for a DIV to slide down. […]

  102. Kosta Krauth Says:

    Here is a prototyped version of the slider, with dynamic heights and automatic upsliding when 2 divs are attempted to be opened at the same time. Tested in Firefox2 and IE7. Hope you find it useful! Note that you will need to change your div style as well to:

    var timerlen = 5;
    var slideAniLen = 250;

    var timerID = new Array();
    var startTime = new Array();
    var obj = new Array();
    var endHeight = new Array();
    var moving = new Array();
    var dir = new Array();

    function slidedown(objname){
    if(moving[objname])
    return;

    if($(objname).style.height != “0px”)
    return; // cannot slide down something that is already visible

    $(objname).setStyle({’height’ : $(objname).scrollHeight + ‘px’});
    moving[objname] = true;
    dir[objname] = “down”;
    startslide(objname);
    }

    function slideup(objname){
    if(moving[objname])
    return;

    if($(objname).style.height == “0px”)
    return; // cannot slide up something that is already hidden

    moving[objname] = true;
    dir[objname] = “up”;
    startslide(objname);
    }

    function startslide(objname){
    obj[objname] = $(objname);

    endHeight[objname] = parseInt(obj[objname].style.height);
    startTime[objname] = (new Date()).getTime();
    if(dir[objname] == “down”){
    obj[objname].style.height = “1px”;
    }

    timerID[objname] = setInterval(’slidetick(” + objname + ”);’,timerlen);
    }

    function slidetick(objname){
    var elapsed = (new Date()).getTime() - startTime[objname];

    if (elapsed > slideAniLen)
    endSlide(objname)
    else {
    var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
    if(dir[objname] == “up”)
    d = endHeight[objname] - d;

    obj[objname].style.height = d + “px”;
    }

    return;
    }

    function endSlide(objname){
    clearInterval(timerID[objname]);

    if(dir[objname] == “up”)
    obj[objname].style.height = “0px”;

    delete(moving[objname]);
    delete(timerID[objname]);
    delete(startTime[objname]);
    delete(endHeight[objname]);
    delete(obj[objname]);
    delete(dir[objname]);

    return;
    }

    function toggleSlide(objname){
    if($(objname).style.height == “0px”){
    // div is hidden, so let’s slide down
    var questions = $(’questions’).getElementsByTagName(’div’);
    var questions= $A(questions);
    questions.each(function(question){
    if(question.style.height != “0px”) slideup(question);
    });
    slidedown(objname);
    }else{
    // div is not hidden, so slide up
    slideup(objname);
    }
    }

  103. Kosta Krauth Says:

    Sorry, the comment ate the div specifications, here it goes again…
    <div id="mydiv" style="display:block; overflow: hidden; height: 0px;">

  104. BillyG Says:

    Thanks Harry. First time reader here. I cam because of a comment you left on the digg site (http://digg.com/design/25_Code_Snippets_For_Web_Designers_2) admonishing some troller’s actions; I’m sure glad I did.

    Your subscriber tally just got incremented by one!

  105. links for 2007-04-13 « the adventures of a baby codemonkey Says:

    […] Harry Maugans » How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS In this tutorial, we will create functions to slide DIVs up and down. It supports multiple animations happening simultaneously, as well as a variable animation length. It’s also time-based, rather than increment based, so it’ll animate the same speed (tags: blog css design howto) […]

  106. All in a days work… Says:

    […] How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS nice DIV hiding effect using 1 toggle or 2 links, works in FF, IE6, and Opera 9.2 - read comments, exactly what I need for my side project! (tags: Collapsible) […]

  107. Sean Says:

    Hey Harry, nice script.

    Just thought I would let you know that you DON’T have to pre-set the height of the div. If you use the Prototype framework, you can use the ‘getHeight’ method, then you can get the height of the div that way. It’s great for divs with dynamic content.

    Cheers!

  108. Arvit Says:

    Hi Harry,

    Nice script. Thanks.

    But I have a situation that I do not want to fix the size of my div. The height is determined at runtime, as it might contain some other elements also (I am developing in c# and will create my div at runtime, based on user option). In that case how to achieve this effect, because without height specified in the style element of the DIV, this script won’t work.

    Cheers

  109. me Says:

    what should i put in the code to make it work in a php file.it works alone but in the wordpress index file stays dormant.thanks

  110. Digg-Style Animated Sliding Comment Box « Josh Davis Says:

    […] sliding boxes similar to what Digg uses for it’s comment system. The two more popular ones, How to Create Digg Comment Style Sliding DIVs with Javascript and CSS and Re: How to Create Digg Comment Style Sliding DIVs with Javascript and CSS, failed to take one […]

  111. Webdesign (css, grafica e altro) » Blog Archive » Best of March 2007 Says:

    […] How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS In this tutorial, we will create functions to slide DIVs up and down. It supports multiple animations happening simultaneously, as well as a variable animation length. It’s also time-based, rather than increment based, so it’ll animate the same speed on most computers; old computers won’t take 10 minutes for a DIV to slide down. […]

  112. Jason Says:

    I’ve been testing Kosta Krauth’s solution to an equivalent of Accordion. However, I’ve to plug-in prototype.js since it’s a prototype-version. Sadly, the codes don’t work. Even by rewriting to a dynamic height structure to Harry’s solution, that too didn’t work.
    Any ideas to get Kosta’s solution to work?

  113. Nick Says:

    ITs cool script but how can i make it one button that can open and close. istead of seprate two links to do that?

  114.   The Best 12 CSS Resources (part 2) by 23Tutorials Says:

    […] http://www.harrymaugans.com/2007/03/06/how-to-creat… - Guide on How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS […]

  115. CodeBit.cn Says:

    不错的文章,非常感谢!

  116. People Meeting Says:

    This is pretty neat. Thanks for taking the time to write it up!!!

  117. Pinguin Says:

    Great script, but do you know why it flashes once just before it totally dissapears in IE? In FF it isn’t flashing btw.

  118. casey Says:

    Nice info - very well done.
    I am trying to include a .swf element inside of the animated div element. The div animates its transitions in and out just fine - but the swf is not obscured(masked) by the sliding motion, and appears to exist on its own (higher up) z-index. Thus, when the div is sliding up, the swf actually is uneffected until the div is closed completely - then it disappears altogether.

    Has anyone come across a work around for this (using a nested swf inside of the target div)

  119. Tom Says:

    So does anyone have a solution for using scrollHeight or any other method to set dynamic heights for each DIV? I’m 99% ready to go with this excellent script, but I’m missing that essential feature — setting heights manually is not an option. I’ve tried to understand how to implement it myself but I fail, miserably…

  120. kk Says:

    kk..tteessttiinngg

  121. Scylix™ Hoque Says:

    For those of you who want a SINGLE BUTTON for slide Up and Down
    , simply type slideup(objname); in the slidedown function as shown;

    function slidedown(objname){

    if(document.getElementById(objname).style.display != “none”) {
    slideup(objname);
    return; // cannot slide down something that is already visible
    }

    }

    and slidedown(objname); in the slideup function as shown;

    function slideup(objname){

    if(document.getElementById(objname).style.display == “none”) {
    slidedown(objname);
    return; // cannot slide up something that is already hidden
    }

    }

  122. Josh Davis » Blog Archive » Digg-Style Animated Sliding Comment Box Says:

    […] animated sliding boxes similar to what Digg uses for its comment system. The two more popular ones, How to Create Digg Comment Style Sliding DIVs with Javascript and CSS and Re: How to Create Digg Comment Style Sliding DIVs with Javascript and CSS, failed to take one […]

  123. Olivier Suritz Says: