views:

217

answers:

2

I'm really not that good at Javascript and that, so I need another bit of help. I want to be able to do a quick bit of AJAX using PHP then when the ajax response is finished show the response in a div and SLIDE it down nicely.

The basic AJAX side of it is no problem. But I want to be able to have it slide nicely without using any framework like jQuery or MooTools. Mainly for learning, but there are other reasons. So, any help on a very simple way od doing so would be handy. I can't really find much online. If I have to use jQuery then I guess I can, I have played about with it but I'm not a fan of Javascript at the best of times...

So yeah, pretty much any advice/tips/thoughts/help would be really handy!

A: 

Personally, I'd just use JQuery. If you want to see how they do it, then download the developer version of the library and look at the code.

If you're not a fan of javascript, then use a library, it means you have to write less.

Paddy
I know, but... I kind of really need to be able to do this without a library if I can work it.
rich
Then go with the first part of the answer - have a look at the code in the JQuery library and write your own version.
Paddy
+1  A: 

I guess the basics would be something of a timeOut() in combination with increasing the height until it is full height:

  1. set the display of the element to none
  2. get the full height of the element, something like:
    document.getelementById('IDofElement').style.height
  3. set the height to 0 and the display to something like block
  4. set a timeOut() and increase the height in the called function, activate a new timeOut() if the element is not already full height.

The only real disadvantage of not using a library would be that you would have to test in a lot of different browsers and perhaps make modifications according to the browser used. Libraries have already solved that problem for you.

jeroen
This seems like a good way to go... shall have a play
rich
Okay, playing with it it all makes sense indeed. However, I guess it needs to have the height already set in the CSS? Or is there a way for it to set the height variable? Sorry for the questions!
rich
I normally use jQuery, but I think that **document.getelementById('IDofElement').style.height** can be used to both set and get the height.
jeroen
I couldnt work out how to get the height of the div when the ajax request was in it without specifiying the height automatically... worked it using this to get the full height BEFORE setting it to 0:var fHeight = document.getElementById('slideDiv').offsetHeight;
rich
and if needed here is a working version+another question (answered):http://stackoverflow.com/questions/1673336/ajax-response-that-slides-open-a-div
rich