General Question

Vincentt's avatar

How do you have Ajax requests fade in with jQuery?

Asked by Vincentt (8094points) January 3rd, 2009

I’m toying around with jQuery (without really knowing Javascript) and am trying to load another page (that’s carrying the text “Yo”) into the first page using AJAX. Now, I can do that part, but I’d like it to fade in and can’t figure out how to do that. With some help from the #jquery IRC chat I managed to have it fade in, however, after the AJAX request it’s also displayed immediately, so it’s showed twice. You can see what I’m doing at this page.

Any suggestions on how to do this (I suppose it’s not that difficult) would be appreciated :)

Observing members: 0 Composing members: 0

5 Answers

richardhenry's avatar

I’m not entirely sure how you would do this in jQuery since I use Prototype, but my usual method is:

1) Load the content into a hidden container
2) onSuccess, fade in the hidden container housing the content

I’m sure there’s a similar method in jQuery.

jrpowell's avatar

This might help. I don’t really know jquery but I just played around a bit.

funkdaddy's avatar

$(“p.addBlock”).click(function(event){
$(“div.main”).load(“yo.html”, showYo);
});

is putting yo.html in there once, and then your function showYo is doing it again, so you’re getting two of the same document added.

Either one of the methods will work on it’s own.

Vincentt's avatar

@richardhenry – thanks, I think I might get somewhere with that.

@johnpowell – thanks… Unfortunately, when using $(“p.addBlock”).click instead of an href it doesn’t work for me :(

@funkdaddy – I know, but I can’t provide the showYo function with the responseText without calling load() (where showYo is the second argument).

Vincentt's avatar

Thanks Richard, your method did the trick :)
Though I still think it’s a bit cumbersome…

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther