亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在滾動位置添加一個類

在滾動位置添加一個類

大話西游666 2023-12-04 17:06:13
我有一個 div,我想在頁面上保持相對位置,直到滾動位置到達 div 的頂部,然后通過添加類來應用固定浮動。我有我認為應該有效的代碼;但是,無法讓它做任何事情。滾動時,div 保持相對狀態,并且不會應用該類來修復對象。$(function() {  var a = function() {    var b = $(window).scrollTop();    var c = $("#header");      var d = c.offset();      if(b > d){ alert(d); c.addClass("header-fixed"); }      else { c.removeClass("header-fixed");  }};});這是CSS.header-fixed { position: fixed; top: 0; left: 0; right: 0; }#header {    z-index: 1000;    float: left;    width: 100%;    z-index: 9999998;}我在標題上方有一個 div,其高度可能會波動,因此我想動態計算從標題頂部到頁面頂部的距離。每當滾動位置到達div頂部的位置時,我想添加 header-fixed 類。如果滾動位置小于該位置,我想刪除Class header-fixed 以再次顯示標題上方的div。HTML:<div id="header_container"><div id="header" class="background-white border-bottom-navy-dark box-shadow-navy-dark"><div id="header_1" ><a href="index" class="no-decoration"><img class="logo" src="images/12345.png"  alt=""/><div class="display-none-mobile"><h1 class="title1 color-gold">HEADER 1</h1><h2 class="subtitle color-navy-dark">SUB HEADER</h2></div></div></a>  <?php /*---- header left ----*/ ?><div id="header_2"><a href="javascript:void(0)" class="cart-link no-decoration color-gold material-icons">shopping_cart</a><a href="javascript:void(0)" class="account-link no-decoration color-gold material-icons">person</a><a href="javascript:void(0)" class="menu-link no-decoration color-gold material-icons">menu</a></div>  <?php /*---- header right ----*/ ?></div>  <?php /*---- header  ----*/ ?></div>  <?php /*---- header site container ----*/ ?></div>  <?php /*---- header container ----*/ ?>
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關注
  • 189 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號