1

i use this script to load content of some div, inside another div:

$(function() {
        $('#menu a').click(function(e) {
            e.preventDefault();
            var h = $(this).attr('href');
            $('#aqui').hmtl($(h).html()).fadeOut('slow').fadeIn('slow');
            //alert(h);
        });
    });

But, as you can see here: http://jsfiddle.net/8rB3S/, the content is load before fadeOut() effect.

i try this tip: https://stackoverflow.com/a/2745494/588842, but with .html(), and this not work.... this only fadeOut and dont fadeIn

Something like that: $('#aqui').fadeOut('slow').hmtl($(h).html, function(){$(this).fadeIn('slow');})

Community
  • 1
  • 1
Preston
  • 2,135
  • 7
  • 29
  • 47

3 Answers3

2

html() is synchronous, passing it a callback function will not do anything.

fadeOut(), on the other hand, is asynchronous. So, call it first and provide a callback function that modifies the markup, then fades the element back in:

$("#aqui").fadeOut("slow", function() {
    $(this).html($(h).html()).fadeIn("slow");
});
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
1

I am not sure what is the desired effect, but try below code,

DEMO: http://jsfiddle.net/skram/8rB3S/2/

$(function() {
    $('#menu a').click(function(e) {
        e.preventDefault();
        var h = $(this).attr('href');
        $('#here').fadeOut(100, function () {
            $(this).html($(h).html())           
           .fadeIn('slow');
        });
    });
});

or

DEMO: http://jsfiddle.net/skram/8rB3S/1/ (used #here as that seems to be where you wanted it)

$(function() {
    $('#menu a').click(function(e) {
        e.preventDefault();
        var h = $(this).attr('href');
        $('#aqui')
           .hide()
           .html($(h).html())           
           .fadeIn('slow');        
    });
});
Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
0

use the callback in fadeout fadein functions :

$(function() {
        $('#menu a').click(function(e) {
            e.preventDefault();
            var h = $(this).attr('href');
            $('#aqui').fadeOut('slow', function(){
                $(this).html($(h).html());
                $(this).fadeIn('slow');
            }):
        });
});
Mouloud
  • 3,715
  • 1
  • 26
  • 20