How to change class Div, which is fixed, when it's 570px.



  • How to change the class Div, which is fixed, when it's 570px. I found an article on the Internet, but they change the savage style, that's the code:

    if ((typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0) >= 570) {
          $("div #true").css({
            'background-color':'#54a58b'
          });
    };
    

    How to change the code to change the diving class.



  • Example of your mission to jQuery:

    Demo: http://codepen.io/anon/pen/xZEPPz

    $(window).scroll(function(e) {
      var height = $(this).scrollTop();
      $('#nav-fixed')[height >= 570 ? 'addClass' : 'removeClass']('active').text(height+'px');
    });
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2