簡體   English   中英

jQuery選擇的菜單項和選項卡

[英]jQuery selected menu item and tabs

有問題的頁面-http://brettcolephotography.com/services.html

如果用戶通過遵循外部鏈接到達特定標簽(每個標簽具有單獨的網址),我的jQuery當前菜單項突出顯示的代碼將無法與我的標簽頁一起使用

我有一點讓我當前的菜單項帶有下划線,總體來說效果很好

$(document).ready(function(){
    $('#bcp-nav a').each(function(index) {
        if(this.href.trim() == window.location)
            $(this).addClass("selected");
    });
});

我正在使用jQuery選項卡的EasyTabs(由Alfa Jango設計)實現,效果也很好。 如果您使用主導航並從一頁轉到服務頁面,則服務會帶有下划線,但是如果您通過外部鏈接指向任何選項卡,則服務不會突出顯示。

例如,請從此處開始-http://brettcolephotography.com/services.html#photo-licensing

嘗試使用此:

$(document).ready(function(){
    var loc = window.location.href.replace(window.location.hash, '');
    $('#bcp-nav a').each(function(index) {
        if(this.href.trim() == loc)
            $(this).addClass("selected");
    });
});

我剛剛對其進行了測試,並且可以正常工作。

要停止頁面跳轉到ID,請嘗試使用以下方法:

setTimeout(function() {
  if (location.hash) window.scrollTo(0, 0);
}, 1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM