![](/img/trans.png)
[英]Is it possible to disable a .scroll function when a user clicks an anchor link that scrolls the page?
[英]Is it possible to disable only the anchor scroll
我實際上有一個項目列表,借助href(例如,#mat顯示菜單),可以打開每個不同的菜單
<div class ="row d-none d-lg-block classer no-gutters ">
<h4>Order by
<a class = "navigation" href="#mat" id="navMat" >localisation</a> /
<a class = "navigation" href="#new" id="navNew" >new</a>
和這個jQuery,以突出顯示當前活動項(例如:本地化)
jQuery( document ).ready(function() {
jQuery('.navigation').on('click', function(e){
jQuery('.navigation').removeClass('navigationU');
this.className = 'navigationU navigation';
})
});
問題是我希望此href在當前活動項目下划線,以打開菜單,但它會滾動到該菜單,因此我不想要它。
我已經嘗試過e.preventDefault();
但我禁用了所有功能:滾動,以及菜單的下划線和顯示。
你有什么主意嗎 ? 謝謝
嘗試這個:
$(document).on('click', '[href^="#"]', function(e) {
location.hash = e.target.hash;
e.preventDefault();
});
它將禁用所有以#
開頭並重新創建的更新鏈接,以更新地址欄中的哈希值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.