In the footer I call the function fxScrollTop with params see below
bib('.header').fxScrollTop({
pixels: 25,
class: 'fixed',
});
bib('.content').fxScrollTop({
pixels: 25,
class: 'fixedHeader',
});
Below the function
function bib(selector){
let elementAll;
if(typeof selector !== 'object'){
elementAll = document.querySelectorAll(selector);
}
return{
fxScrollTop: (props) => {
for(const prop in props){
if(prop == 'pixels'){
var pixels = props[prop];
}
if(prop == 'class'){
var newclass = props[prop];
}
}
for(let i=0; i < elementAll.length; i++){
elm = elementAll[i];
}
window.onscroll = function (e) {
var pixelsFromTop = window.pageYOffset;
if(pixelsFromTop > pixels){
elm.classList.add(newclass);
}else{
elm.classList.remove(newclass);
}
}
}
}
}
The function works but only on the last call and not twice. How can I call this function multiple times with different params?