簡體   English   中英

Onscroll 切換無法添加或刪除類

[英]Onscroll toggle failing to add or remove class

我對 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