I have these functions to add listeners to change classes:
function dropClass(el, style){
if(el.classList.contains(style) === true){
el.classList.remove(style);
};
};
function addClass(el, style){
if(el.classList.contains(style) === false){
el.classList.add(style);
};
};
function onLoad(myFunction){
document.addEventListener('load', myFunction);
};
function onClickAdd(el, style){
el.addEventListener('click', addClass(el, style));
};
function onClickRemove(el, style){
el.addEventListener('click', dropClass(el, style));
};
function onMouseOverAdd(el, style){
el.addEventListener('mouseover', addClass(el, style));
};
function onMouseOverRemove(el, style){
el.addEventListener('mouseover', dropClass(el, style));
};
...and have some of them interacting with each other to where they actually work:
onLoad(addClass(body, 'openEyes'));
onLoad(addClass(h1, 'slideDown'));
onLoad(addClass(p1, 'slideRight'));
onLoad(addClass(p2, 'slideLeft'));
onLoad(addClass(p3, 'slideUp'));
...but when I try to use the listener event functions they do not work based on the defined action but on the page load. What's wrong?
An example of the type of function stacking that doesn't work:
onLoad(onClickAdd(el, style);
It "works" in that it adds the class, but it doesn't do it on the listener event and only on the page load which it shouldn't do. This is the site I'm building and trying to do a minimalist design without its being too static (http://myskills.epizy.com/DynamicSite.html) , and these functions should work but for some reason don't.