Twitter bootstrap 3 不同屏幕尺寸上的固定导航栏

Twitter bootstrap 3 不同屏幕尺寸上的固定导航栏,twitter-bootstrap-3,navbar,Twitter Bootstrap 3,Navbar,有没有一种方法可以使用Bootstrap 3 Fixed Navbar将其固定在md+上的顶部,但在较小的设备上固定在底部 目前,根据屏幕宽度隐藏和显示两个单独的导航。更希望有一个导航,将根据屏幕大小粘贴,但不知道如何 我是前端,不懂JavaScript,所以请在任何可能包含JS的说明中详细说明 提前感谢。使用jQuery非常简单 只需在加载时检查浏览器的宽度,如果宽度等于或小于768像素,请将navbar fixed bottom添加到您的navbar jQuery: var width =

有没有一种方法可以使用Bootstrap 3 Fixed Navbar将其固定在md+上的顶部,但在较小的设备上固定在底部

目前,根据屏幕宽度隐藏和显示两个单独的导航。更希望有一个导航,将根据屏幕大小粘贴,但不知道如何

我是前端,不懂JavaScript,所以请在任何可能包含JS的说明中详细说明


提前感谢。

使用jQuery非常简单

只需在加载时检查浏览器的宽度,如果宽度等于或小于768像素,请将
navbar fixed bottom
添加到您的navbar

jQuery:

var width = $(window).width(),
    height = $(window).height();
if ((width <= 768)) {
    $('.navbar').addClass('navbar-fixed-bottom');
}
var width=$(窗口).width(),
高度=$(窗口).height();

如果((width如果您不想在这种情况下使用javascript,这里是我的解决方案

因为您应该使用:

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
因此,正如您所看到的,您可以使用
navbar-fixed-top
来代替
navbar-fixed-bottom
来继承
navbar-fixed-top
navbar-fixed-bottom
类,具体取决于设备类型(xs、sm、md、lg)

$(window).on('load resize', function() {
    if($(window).width() <= 768) {
        $('.navbar').addClass('navbar-fixed-bottom');
    } else {
        $('.navbar').removeClass('navbar-fixed-bottom');
    }
});
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<nav class="navbar navbar-default navbar-fixed-bottom" role="navigation">
<nav class="navbar navbar-default navbar-position" role="navigation">
/* LESS */

@media (max-width: 767px) {
    navbar-position {
        .navbar-fixed-bottom;
    }
}

@media (min-width: 768px) and (max-width: 991px) {
    navbar-position {
        .navbar-fixed-bottom;
    }
}

@media (min-width: 992px) and (max-width: 1199px) {
    navbar-position {
        .navbar-fixed-top;
    }
}

@media (min-width: 1200px) {
    navbar-position {
        .navbar-fixed-top;
    }
}