如何让内容部分在导航点击时淡入淡出? 然后我如何让一个特殊的页面加载到页面?jQuery淡入淡出内容
代码:
$(document).ready(function(){
$("a").click(function(e){
e.preventDefault();
$('#content').children('section').hide();
$('#' + $(this).attr('href')).show();
});
});
如何让内容部分在导航点击时淡入淡出? 然后我如何让一个特殊的页面加载到页面?jQuery淡入淡出内容
代码:
$(document).ready(function(){
$("a").click(function(e){
e.preventDefault();
$('#content').children('section').hide();
$('#' + $(this).attr('href')).show();
});
});
您可以使用.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()
});
你必须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();
});
});
谢谢你,我用了你的一些东西,现在好像我这样做,它是伟大的,我认为..但我怎么能这样做,其中一页是在加载页面可见,而不是所有(观看链接在评论另一个答案!) – Tekkzz
谢谢你,看看链接:[链接](http://nitram0598.zapto.org),但如果我cahnge页它是LD下,然后moves..do你知道我的意思?我如何解决它? – Tekkzz
你想先淡出元素然后显示下一个 –
是的,这是我的想法 – Tekkzz