3

I am trying to create a side menu such that when user click on a link the current content in the div(middle of the page) should fadeout and new page content should fadeIn and I created this method:

<script type="text/javascript">
    $('a').click(function() {
        $('#content').html('<img src="ajax-loader.gif" width="100" alt="loading">').show();
        var page = $(this).attr('href');
        $('#content').hide().load(page).fadeIn('slow');
        return false;
    });
</script>

However, the effect is not as expected, anyone know how to enhance this method? I expected to fadeout current content to background page and fadeIn new content.
But the current content just disappears

My html code:

<body>
    <h1><img src="images/cooltext679404844.png"/></h1>
    <ul id="nav" class="mmenu" type="none">
        <li><a href="contact.php"> Contact </a></li>
        <li><a href="register.php"> Register </a></li>
        <li><a href="login.php"> Login</a></li>
        <li><a  href="upload.php"> Submit paper </a></li>
        <li><a  href="tabs.php"> tabs menu test </a></li>
        <li><a href="time-frame.php">profile</a></li>
        <li><a  href="status-reviews.php">check status of reviews</a></li>
    </ul>
    <p style="font-size: small;text-align: center;bottom: 0px;left: 300px; line-height: 0%;position:fixed; background-color: #cc8800">
        <a target="content" href="about.php">About us</a> | <a target="content" href="terms.php">Terms of service</a> | <a target="content" href="policy.php">Privacy Policy</a>
    </p>
    <div id="content"></div>
</body>
Milad Rashidi
  • 1,296
  • 4
  • 22
  • 40
Samer El Gendy
  • 1,683
  • 2
  • 23
  • 45
  • I think it's because you're chaining the `load` and the `fadeIn` methods. The `load` works in an asynchronous manner – pomeh Apr 24 '12 at 09:03

2 Answers2

1

Try:


$("#content").fadeOut('slow', function(){
    $("#content").load(page, function () {
            $(this).fadeIn('slow');
    });
});     
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
0

Use a Callback in your load. Otherwise it fades in instantly:

var content = $('#content');
content.fadeOut().load(page, function() {
    content.fadeIn();
});
binarious
  • 4,568
  • 26
  • 35