Skip to content

How to have the navbar in Twitter Bootstrap stay fixed for screen width less than 768px Update

January 14, 2016

Here is an update on the previous post I have made in that you may need to automatically allow the top bar navigation to become fixed and also run the code on load.

So here is the revised code.

$(document).ready(function () {

var screenxs =768;

if (window.innerWidth <= screenxs) {
$(“#topbar”).removeClass(“hide”);
$(“#topbar”).addClass(“navbar-fixed-top”);
} else {
$(“#topbar”).removeClass(“navbar-fixed-top”);
$(“#topbar”).addClass(“hide”);
}

$(window).resize(function () {
if (window.innerWidth <= screenxs) {
$(“#topbar”).removeClass(“hide”);
$(“#topbar”).addClass(“navbar-fixed-top”);
} else {
$(“#topbar”).removeClass(“navbar-fixed-top”);
$(“#topbar”).addClass(“hide”);
}
});
});

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: