html - make two similar javascript functions work together -
i started javascript recently. found piece of code changes class of object on scroll using pure javascript. here code -
window.onscroll = function() { if (window.scrolly > 1) { document.getelementbyid('nav2').classname = "after"; } else { document.getelementbyid('nav2').classname = "before"; }}; window.onscroll = function() { if (window.scrolly > 1) { document.getelementbyid('list').classname = "ul2"; } else { document.getelementbyid('list').classname = "ul"; }};
the problem in code second function runs , first 1 not run until remove second function. please suggest pure javascript method solve issue
problem because when saying second time window.onscroll=somefun
it's overwriting existing one. call second function onscroll
.
just write every thing in 1 function bellow
window.onscroll = function() { if (window.scrolly > 1) { document.getelementbyid('nav2').classname = "after"; document.getelementbyid('list').classname = "ul2"; } else { document.getelementbyid('nav2').classname = "before"; document.getelementbyid('list').classname = "ul"; }};
Comments
Post a Comment