- This topic has 5 replies, 2 voices, and was last updated 5 years, 3 months ago by
David.
-
AuthorPosts
-
December 17, 2020 at 6:25 am #1584320
Fabio
Hi all i just understood that sticky navigation requires jquery to work, but in my website i disabled jquery and i would like to know if it is possible to use fixed navigation even without usign Jquery, i dont’t know, with Vanilla or Css or what esle
thank youDecember 17, 2020 at 6:37 am #1584338Fabio
ok i found this:
https://generatepress.com/forums/topic/dont-want-to-use-jquery-and-still-want-sticky-navigation-with-css/i had to make the css on .site-header and it seems to works, but, is there any ways to emulate the jquery functions like showing the fixed header only when scrolling up?
December 17, 2020 at 6:52 am #1584509David
StaffCustomer SupportHi there,
its not possible to do the transition with CSS alone, it would require some JS to do that. We will be replacing jQuery in the next update with Vanilla JS.
December 17, 2020 at 7:22 am #1584548Fabio
uh uh love you so much ! Vanilla Vanilla 🙂
i was just testing this: https://codingreflections.com/hide-header-on-scroll-down/
it works for me adding a padding-top:50px on body elementbut i will wait for your news update !!
thank you
December 17, 2020 at 7:42 am #1584566Fabio
temporary solution:
<script>
(function(){var doc = document.documentElement;
var w = window;var prevScroll = w.scrollY || doc.scrollTop;
var curScroll;
var direction = 0;
var prevDirection = 0;var header = document.getElementById(‘masthead’);
var checkScroll = function() {
/*
** Find the direction of scroll
** 0 – initial, 1 – up, 2 – down
*/curScroll = w.scrollY || doc.scrollTop;
if (curScroll > prevScroll) {
//scrolled up
direction = 2;
}
else if (curScroll < prevScroll) {
//scrolled down
direction = 1;
}if (direction !== prevDirection) {
toggleHeader(direction, curScroll);
}prevScroll = curScroll;
};var toggleHeader = function(direction, curScroll) {
if (direction === 2 && curScroll > 50) {header.classList.add(‘hide’);
prevDirection = direction;
}
else if (direction === 1) {
header.classList.remove(‘hide’);
prevDirection = direction;
}
};window.addEventListener(‘scroll’, checkScroll);
})();
</script>
<style>
body{padding-top:50px}
#masthead {
position: fixed;
height: 50px;
top: 0px;
width: 100%;
z-index: 100;
transition: all .3s ease;}
#masthead.hide {
top: -51px;
}
</style>December 18, 2020 at 2:19 am #1585500David
StaffCustomer SupportYou’re welcome – and thanks for sharing your solution 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.