According to Bootstrap 3 docs I have added following attributes to a navbar:
For the users who are looking for an answer in pure Javascript, this is how you can do it by using pure Javascript:
window.onscroll = (e) => {
let scrollValue = window.scrollY;
if (scrollValue > 120) {
document.querySelector('.navbar').classList.add('affix');
} else{
document.querySelector('.navbar').classList.remove('affix');
}
}