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

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

修復了頁面標題與頁面上的錨點重疊的問題

修復了頁面標題與頁面上的錨點重疊的問題

藍山帝景 2023-07-06 17:45:33
當我單擊任何錨鏈接時,我的標題與該部分的實際內容重疊。是否可以將其移動到該部分的頂部?我已經在尋找一些解決方案,但它們并不適合我。我嘗試向這些部分添加一個錨類,并且還嘗試了scroll-margin-top,但效果不佳。//header Effekt beim scrollen$(function() {  var shrinkHeader = 100;  $(window).scroll(function() {    var scroll = getCurrentScroll();    if (scroll >= shrinkHeader) {      $('#navbar').addClass('shrink');    } else {      $('#navbar').removeClass('shrink');    }  });  function getCurrentScroll() {    return window.pageYOffset || document.documentElement.scrollTop;  }});// JavaScript Document$(document).ready(function(){    var navTop = $('#navbar').offset().top;var navHeight = $('#navbar').height();var windowH = $(window).height();$('.section').height(windowH);$(document).scroll(function(){    var st = $(this).scrollTop();        //for the nav bar:    if(st > navTop ){        $('#navbar').addClass('fix');        $('.section:eq(0)').css({'margin-top':navHeight});//fix  scrolling issue due to the fix nav bar    }else{        $('#navbar').removeClass('fix');        $('.section:eq(0)').css({'margin-top':'0'});    }        $('.section').each(function(index, element) {        if(st + navHeight > $(this).offset().top && st + navHeight  <= $(this).offset().top + $(this).height()  ){            $(this).addClass('active');                         var id = $(this).attr('id');            $('a[href="#'+id+'"]').parent('li').addClass('active');            // or $('#nav li:eq('+index+')').addClass('active');        }else{            $(this).removeClass('active');                        var id = $(this).attr('id');            $('a[href="#'+id+'"]').parent('li').removeClass('active');            //or $('#nav li:eq('+index+')').removeClass('active');        }            });    });    });//
查看完整描述

1 回答

?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

請在您的 css 代碼中嘗試一下:我剛剛將 top:0 添加到您的導航欄代碼中,并將 margin-top 添加到 html 中的下一個元素,即該部分。我認為 spacer div 沒有必要。


#navbar {

  border-bottom-style: solid;

  border-bottom-width: 1.25px;

  box-shadow: 0px 2.5px 5px rgba(0, 0, 0, 0.2);

  background-color: white;

  height: 128px;

  transition: 0.32s;

  position: fixed;

  top:0;

  width: 1280px;

}


body {

margin-top: 128px;

}


查看完整回答
反對 回復 2023-07-06
  • 1 回答
  • 0 關注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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