how to change navbar style on scroll [solved]

0
hello experts, i have to change my navbar Bg color on scroll but scroll event is not working. i also referred below questions but did not worked. Mendix Forum - Questions   Mendix Forum - Questions   can someone guide me step by step to achieve this.
asked
3 answers
1

Hi Sanjay,

Can you please attach any prototype in which format you are expecting the output to be it will be helpful to give you a solution.

answered
0

Hi Sanjay,

           I hope this one helpful to you.

window.onscroll = function() {myFunction()};

function myFunction() {
  if (document.documentElement.scrollTop > 50) {
    document.getElementById("myP").className = "test"; // here you get to navbar  element div and apply your class name
  } else {
    document.getElementById("myP").className = "";
  }
}

please referral this link https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onscroll2

 

answered
0

hello members finally problem has been solved

i used jquery scroll method to solve this, by the javascript it was not working but when i use jquery code it done.

 

code ------------

--------------------------------------------------------------------------------------------------------

$(window).scroll(function() {        
        var topOfWindow = $(window).scrollTop();  
        if (topOfWindow > 20) {
            $('.nav-layout').addClass("active2");  
            $('.nav-link').addClass("text-dark");                      

        } else {
        $('.nav-layout').removeClass("active2");
        $('.nav-link').removeClass("text-dark"); 
        }

    });

 

i hope it will help to other community members.

answered