views:

534

answers:

4

Hello,

i have this PHP based doc (chatbox) where you can type your message and send it.

Now, i have this fade animation where a message comes in when a message is send. Looks like this:

Javascript:

function stateChanged1() 
{ 
if (xmlHttp1.readyState==4)
{ 
document.getElementById("sent").innerHTML="Sent!";
document.writeform.message.value="";
chat();
}
}

in the body:

<span id="sent"></span>

The problem is then it isnt fading out. What do i have to add to the code and where?

+5  A: 

For Effects like fading out use a framework like JQuery, Prototype or MooTools. They will provide you with ample examples how to apply effects to elements.

Pekka
+1 on jQuery usage.
Adrian Godong
+1 For mentioning the various frameworks available to solve this problem
Vijay Dev
+1  A: 

try jquery you can fadein and fade out an element easly e.i:

$("#sent").fadeIn("slow");
$("#sent").fadeOut("slow");
Yassir
+2  A: 

Add

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;

to your HTML and add this JavaScript Code:

$("#sent").fadeOut("slow");

after this line:

document.getElementById("sent").innerHTML="Sent!";
powtac
Works. but for slow it is going quite fast. And the weird thing of my code is also that if i send a message again, it won't display the 'Sent!' text again. Do you need some kind of extra script for it?
YourComputerHelpZ
To show up the "Send!" message again use $("#sent").fadeIn("fast");
powtac
where to put that...?
YourComputerHelpZ
Maybe before document.getElementById("sent").innerHTML="Sent!"; ?
powtac
+1  A: 

i also recommend that you should use jquery's fade in and fade out function. for a deeper explanation and code samples please goto: http://docs.jquery.com/Effects/fadeOut

ufk