I tried to transform the next piece of JS code into JQuery but It doesn't work. Could you help ?
function initUpdateNavbarOnScroll() {
var navbarc = document.querySelectorAll('#site-navigation-wrap .dropdown-menu>li>a');
window.addEventListener('scroll', () => {
if (window.scrollY >= window.innerHeight) {
navbarc.classList.add('darklinker');
} else {
navbarc.classList.remove('darklinker');
}
});
}
initUpdateNavbarOnScroll();
I've made different try if it helps but any of them works...
// $( "#site-navigation-wrap .dropdown-menu>li>a" ).on( "scroll", function( event ) {
// var navbarc = $( this );
// if (window.scrollY >= window.innerHeight) {
// navbarc.addClass('darklinker');
// } else {
// navbarc.removeClass('darklinker');
// }
// });
// $( window ).scrollY(function() {
// if ($( "site-navigation-wrap .dropdown-menu>li>a" )) {
// navbarc.addClass('darklinker');
// } else {
// navbarc.removeClass('darklinker');
// }
// });
Thx.
if ($( "site-navigation-wrap .dropdown-menu>li>a" ))this will always return true asjQuery()returns an object even if no elements are selected. Also there is no jQuery function namedscrollY()unless you are using some plugin library.querySelectorAlldoesn't work but thequerySelectordo his job. But I want to select them all... I asked to the theme owner and he told me to write it in JQuery because it's load in the theme. They should have a conflict somewhere, i think but don't know where exactly...