gpt4 book ai didi

html - 如何使用固定导航栏控制 anchor 位置?

转载 作者:行者123 更新时间:2023-11-28 03:35:34 28 4
gpt4 key购买 nike

当我单击此 page 上的 anchor 时,即(Due South Australia、SA Dining Guide、SA Style、SA Accommodation Guide、Backpackers Short Breaks Australia)然后由于标题的粘性,该部分向上移动了一点。

最佳答案

在页脚中添加此 java 脚本以添加顶部偏移量。

<script type="text/javascript">
$(document).ready(function(){
// Add smooth scrolling to all links
$(".hashtag a").on('click', function(event) {

// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();

// Store hash
var hash = this.hash;


// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area

var target_offset = $(hash).offset() ? $(hash).offset().top : 0;
//change this number to create the additional off set
var customoffset = 40
$('html, body').animate({scrollTop:target_offset - customoffset}, 1000, function(){

// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
</script>

关于html - 如何使用固定导航栏控制 anchor 位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44500750/

28 4 0