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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -