I am using JQuery and what I want to happen is.
Div fades out using the fadeOut command. It then loads content from a url using the load command. Then once content loaded it fades back in using the fadeIn command.
The code I have is:
$("#myDiv").fadeOut().load('www.someurl.com').fadeIn()
However this does not work. It kind of flashes then loads out then loads in. I think the problem is that the fading is happening before the load is complete.
What should I do
Thanks
jQuery fadeIn() Method The fadeIn() method gradually changes the opacity, for selected elements, from hidden to visible (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeOut() method.
The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in.
The jQuery fadeOut() method is used to fade out a visible element. Syntax: $(selector).fadeOut(speed,callback); The optional speed parameter specifies the duration of the effect.
jQuery fadeToggle() If the elements are faded in, it will make them faded out and if they are faded out it will make them faded in. Syntax: $(selector). fadeToggle();
you can use the load() callback function like this:
$("#myDiv").fadeOut().load("www.someurl.com", function(response, status, xhr) {
$(this).fadeIn();
});
you might want to use the status of the load() call to see if everything was completed properly.
$("#myDiv").fadeOut().load("www.someurl.com", function(response, status, xhr) {
if (status == "error") {
// handle error
}
else
{
$(this).fadeIn();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With