navbar responsiveness with media queries instead of js
This commit is contained in:
parent
2063a32bb9
commit
54a0fa1252
@ -1,47 +1,42 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
window.utils = window.utils || {};
|
||||
window.utils = window.utils || {};
|
||||
|
||||
window.utils.stickynav = function(nav) {
|
||||
var ticking = false;
|
||||
window.utils.stickynav = function (nav) {
|
||||
var ticking = false;
|
||||
|
||||
init();
|
||||
function init() {
|
||||
nav.style.paddingLeft = document.body.getBoundingClientRect().width < 999 ? '90px' : '';
|
||||
window.setTimeout(function() {
|
||||
nav.classList.add('navbar--animated');
|
||||
}, 200);
|
||||
checkScroll();
|
||||
addListener();
|
||||
}
|
||||
init();
|
||||
function init() {
|
||||
window.setTimeout(function () {
|
||||
nav.classList.add('navbar--animated');
|
||||
}, 200);
|
||||
checkScroll();
|
||||
addListener();
|
||||
}
|
||||
|
||||
// checks scroll direction and shows/hides navbar accordingly
|
||||
function checkScroll() {
|
||||
var sticky = window.scrollY > 0;
|
||||
sticky = sticky && window.innerHeight < (document.scrollingElement.scrollHeight - 50);
|
||||
nav.classList.toggle('navbar--sticky', sticky);
|
||||
ticking = false;
|
||||
}
|
||||
// checks scroll direction and shows/hides navbar accordingly
|
||||
function checkScroll() {
|
||||
var sticky = window.scrollY > 0;
|
||||
sticky = sticky && window.innerHeight < (document.scrollingElement.scrollHeight - 100);
|
||||
nav.classList.toggle('navbar--sticky', sticky);
|
||||
ticking = false;
|
||||
}
|
||||
|
||||
function addListener() {
|
||||
window.addEventListener('scroll', function(e) {
|
||||
if (!ticking) {
|
||||
window.requestAnimationFrame(checkScroll);
|
||||
ticking = true;
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
window.addEventListener('resize', function() {
|
||||
nav.style.paddingLeft = document.body.getBoundingClientRect().width < 999 ? '90px' : '';
|
||||
}, false);
|
||||
}
|
||||
function addListener() {
|
||||
window.addEventListener('scroll', function (e) {
|
||||
if (!ticking) {
|
||||
window.requestAnimationFrame(checkScroll);
|
||||
ticking = true;
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
})();
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
utils.stickynav(document.querySelector('.js-sticky-navbar'));
|
||||
|
||||
|
||||
@ -21,6 +21,13 @@
|
||||
box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
@media (max-width: 999px) {
|
||||
|
||||
.navbar {
|
||||
padding-left: 90px;
|
||||
}
|
||||
}
|
||||
|
||||
.navbar__logo {
|
||||
transition: all .2s ease;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user