Link to home
Start Free TrialLog in
Avatar of askurat1
askurat1Flag for United States of America

asked on

FadeIn and FadeOut with jQuery

I am having some trouble fading in and out my Submit button. The animation works as I want but with a minor issue.

When I enter in the form info, on my contact page, and hit Submit, the Submit button fades out and the success message fades in. This is correct except the fades on the Submit button doesn't seem to finish fading before display is set to none. It animates close to the end and then disappears before it finishes. This makes the animation look jerky.
I want the animation to be smooth all the way to the end.

Here is my site: www.skurat.com
Submit an email form and you will see what I am talking about.

Any help would be great.

Thanks,
Tony
Avatar of Gary
Gary
Flag of Ireland image

Where is the fadeout code rather than searching for it..?
I suspect you probably just need to cover it with a function

$('submitid').fadeOut('slow', function() {
    // add code to fade in success

});
Avatar of askurat1

ASKER

Here is the code:
var getName = $('#name').val(),
			    message = '<h5>Thanks, <b>' + getName + '</b>!</h5><h5>Your message has been sent.</h5>'			
			
            $('#submit, .sending').fadeOut(1600);

            $('.mess').delay(4000).html(message).fadeIn('fast', function () {
			   $('#form').clearForm();
			   $(this).delay(5000).fadeOut('slow', function() {         
                $('#submit').fadeIn('slow');
            });	
			});

Open in new window


I have already tried what you said and it doesn't seem to work.
This code can be found in custom.js.
Should the success be fading in as the submit fades out or waiting til the submit button is completely faded out?
It doesn't really matter. I just want the button to fade correctly.
SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not sure how this is different from what I have.
Updated:
$('#submit, .sending').fadeOut('slow', function (){
				$('.mess').delay(1000).html(message).fadeIn('fast', function () {
			   $('#form').clearForm();
			   $(this).delay(5000).fadeOut('slow', function() {         
                $('#submit').fadeIn('slow');
            });	
			});				
			});

Open in new window


Still does the same thing.
I don't have time right now to rewrite your code but you need to encapsulate the order of things so they run after each other.
So in your ajax call set the sending to show, on successful call back hide the submit/sending and show the success message or an error message
I'm still not understanding. To simplify things I have removed sending from showing.
$('#submit').fadeOut('slow', function (){
		$('.mess').delay(1000).html(message).fadeIn('fast', function () {
			   $('#form').clearForm();
			   $(this).delay(5000).fadeOut('slow', function() {         
                                   $('#submit').fadeIn('slow');
                           });	
		  });				
});

Open in new window


I'm not sure what I'm doing wrong.

Thanks for the help.
Does this work for you
http://jsfiddle.net/v7JB8/26/
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I found the solution.