jquerydynamic-datafadeinfadeoutfading

fadeOut current content and fadeIn new content jquery


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>

Solution

  • Try:

    
    $("#content").fadeOut('slow', function(){
        $("#content").load(page, function () {
                $(this).fadeIn('slow');
        });
    });