简体   繁体   English

Onscroll 切换无法添加或删除类

[英]Onscroll toggle failing to add or remove class

I am fairly new to js but I am trying to get this to fire so that my nav div will stick to the top of the screen I am not sure if my window on the scroll function is firing correctly.我对 js 相当陌生,但我试图让它触发,以便我的导航 div 会粘在屏幕顶部我不确定我的滚动功能窗口是否正确触发。

$(document).ready(function() {
  "use strict";

  $('#commons').window.onscroll(function(direction) {
    $('.main-nav').toggleClass('fixed-nav', direction == 'down');
    $('.main-nav a').removeClass('active');
    $('.main-nav a.commons-btn').addClass('active');
  }, {
    offset: '90px'
  });
});
$(document).ready(function(){       
    var scroll_pos = 0;
    $(document).scroll(function() { 
        scroll_pos = $(this).scrollTop();
        if(scroll_pos > 210) {
             // Type here your script, this will run on scrolling
        } else {
            // This script will run when the scroll bar is on the top 
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM