2013-12-15 119 views
1

如何让内容部分在导航点击时淡入淡出? 然后我如何让一个特殊的页面加载到页面?jQuery淡入淡出内容

代码:

$(document).ready(function(){ 
    $("a").click(function(e){ 
    e.preventDefault();  
    $('#content').children('section').hide();  
    $('#' + $(this).attr('href')).show(); 
    }); 
}); 

回答

1

您可以使用.fadeIn()和.fadeOut()来做到这一点

$(document).ready(function() { 
    $("a").click(function (e) { 
     e.preventDefault(); 

     //use .stop() so that the animation queue is cleared 
     //show the elemet with the given href as the id 
     var $target = $('#' + $(this).attr('href')).stop(true, true); 

     //hide all sections under #content except the current section 
     var $secs = $('#content > section').not($target).stop(true, true).filter(':visible'); 
     if ($secs.length) { 
      $secs.fadeOut(function() { 
       $target.fadeIn(); 
      }); 
     } else { 
      $target.fadeIn(); 
     } 
    }); 
    $('#content > section').not('#home').hide() 
}); 
+0

谢谢你,看看链接:[链接](http://nitram0598.zapto.org),但如果我cahnge页它是LD下,然后moves..do你知道我的意思?我如何解决它? – Tekkzz

+0

你想先淡出元素然后显示下一个 –

+0

是的,这是我的想法 – Tekkzz

1

你必须fadeout的元素,然后再fadeIn目标元素后达到你想要的效果。

尝试,

$(document).ready(function(){ 

    $('#content').children('section').not('#home').hide(); 

    $("a").click(function(e){ 
    e.preventDefault();  
    $('#content').children('section').stop().fadeOut();  
    $('#' + $(this).attr('href')).stop().fadeIn(); 
    }); 
}); 
+0

谢谢你,我用了你的一些东西,现在好像我这样做,它是伟大的,我认为..但我怎么能这样做,其中一页是在加载页面可见,而不是所有(观看链接在评论另一个答案!) – Tekkzz