I'm new to JavaScript, i seem to have got myself in a tricky situation. Currently i have some code which below 200px adds a class to make the navbar sticky. The code which have added can be found below.
function navbarCollapse () {
if ($("#mainNav").offset().top > 200) {
$("#mainNav").addClass("navbar-shrink");
$("#mainNav").removeClass("navbar-font");
} else {
$("#mainNav").removeClass("navbar-shrink");
$("#mainNav").addClass("navbar-font");
}
}
//Execute The Collapsing Navbar Function
navbarCollapse();
//Scroll Event
$(window).scroll(navbarCollapse);
The problem I'm facing is 200px on one device is completely different on another device such as a large monitor
I need to be able to calculate the height of a devices view-port, and then execute the code accordingly.
Any help would greatly be appreciated. Like i said I'm new to JavaScript and I'm probably missing something simple.