2013-12-15 89 views
0

我想在这个图像上做点什么,当我在菜单上选择另一个东西时,主要内容会增加。 http://i.stack.imgur.com/h4D8H.gif对Jquery的影响

我在以某种方式如何做到这一点知道,我使用的是选项卡的网站相同的概念,这样的事情:

$(function(){ 
       $("#content:First").show(); 
       $("#wrap a").click(function(){ 
        $(".aba").hide(); 
        var div = $(this).attr('href'); 
        $(div).fadeIn('slow'); 
        $('#menu li').css('background', '#03c0f3'); 
        $(this).parent('li').css('background', '#2ADAF1'); 

        return false; 
       }); 

我想知道是什么效果我可以申请div(在$(div)上)来变成这样,或者如果有更好的方法来做到这一点。

+0

您是否反对创建可滚动内容并简单地滑动到锚? – d3c0y

回答

0

像@ d3c0y的想法为什么不把它作为一个可滚动的内容,只是滑到click()的内容。

$('nav a').click(function (e) { 
    e.preventDefault(); 
    var div = $(this).attr('href'), 
     //get the contents offset top position 
     offsetTop = $(div).offset().top; 
    //animate scrolling to the contents 
    $('body, html').animate({ 
     scrollTop: offsetTop 
    }, 'slow'); 
}); 

您也可以申请使用fadeTo()一些衰落效应:

$(div).fadeTo('slow', 1).siblings().fadeTo('slow', 0); 

您还可以删除滚动条,如果你喜欢body {overflow:hidden;},滚动/固定仍然可以工作。

看到这个jsfiddle

0

我不认为有任何预定义的功能适合您的需求。你必须自己使用.animate()来构建它。它应该是这个样子:

$('#navigation a').click(function(){ 
    $('#content').css({ 
     position : 'absolute', 
     top : 0, 
     left : 0 
    }).animate({ 
     top : -$('#content').height() - 1 
    }, 250, function(){ 
     // Change content here 
     // Animate it back 
    }); 
}); 

另外,许多其他网站使用的是什么,你可以在一个页面上提供您的全部内容,并分别滚动(example)。为此,请查看不同的插件,例如this one