简体   繁体   中英

Adding padding -100px when scroll to the id

I have a navigation menu with with anchors to ids and I want to add some padding because part of the content isn't visible due to the navigation bar.

I was searching for some solutions and found this but it doesn't work. Could you help me please?

The website is http://testerks.futurehost.pl/intensedms . #pm is the div id

scrollTop': $target.offset().top - ($('#pm').height() + 50

您可以从 div#pm 的顶部偏移中减去导航的高度,在您的情况下为 82px。

$(window).scrollTop( $target.offset().top - 82)

This CSS tells the browser that, when it scrolls to #pm, to leave a 82px gap.

#pm {
   scroll-margin: 82px;
}

Further documentation and browser support:https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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