2012-11-29 69 views

回答

0

看看在燈絲組網站上會發生什麼,你可以看到低於一定的寬度,正文獲得類nav-menu,並且當尺寸更大時,它將被移除。這是他們的RWD-nav.js完整的評論:

jQuery(function($){ 
$('.nav-primary') 
    // test the menu to see if all items fit horizontally 
    .bind('testfit', function(){ 
    var nav = $(this), 
    items = nav.find('a'); 

    $('body').removeClass('nav-menu');      

    // when the nav wraps under the logo, or when options are stacked, display the nav as a menu    
    if ((nav.offset().top > nav.prev().offset().top) || ($(items[items.length-1]).offset().top > $(items[0]).offset().top)) { 

     // add a class for scoping menu styles 
     $('body').addClass('nav-menu'); 
    };      
}) 

// toggle the menu items' visiblity 
.find('h3') 
    .bind('click focus', function(){ 
     $(this).parent().toggleClass('expanded') 
    }); 

    // ...and update the nav on window events 
    $(window).bind('load resize orientationchange', function(){ 
    $('.nav-primary').trigger('testfit'); 
}); 

}); 

然後在他們的RWD-nav.css,這種重新定位基於寬度

/* Media queries 
------------------------------ */ 

@media screen and (min-width: 640px) { 
    .nav-primary, 
    .nav-primary ul { 
    float: left; 
    } 
    .nav-primary ul { 
    float: left; 
    } 
    .nav-primary li { 
    float: left; 
    font-size: 1.5em; 
    border-bottom: 0; 
    } 
} 

@media screen and (min-width: 910px) { 
    .nav-primary { 
    float: right; 
    clear: none; 
    } 
} 

希望幫助!