2017-06-12 17 views
0

所以我從來沒有見過這個,它讓我瘋狂。希望以前有人遇到過這種情況,並可以指引我朝着正確的方向前進。應該指出的是,這個網站是建立在WP平臺上的。鏈接與定位到特定的div不起作用的錨點

我有一個非常簡單的鏈接設置: <a href="site.com/page-1/#div">

的問題是,當我在任何網頁上,例如「site.com/page-2」當我點擊鏈接沒有任何反應。 ..沒有事件被觸發。

如果我碰巧在「site.com/page-1」上,並且點擊鏈接,它會滑動到相應的div。但是,再次,在任何其他頁面上,鏈接完全不起作用。

回答

0
You have to give id in that specific div and there are multiple divs then you can use else if condition and then just put this jquery in footer. Please also add jquery.min.js before it 

$(document).ready(function{ 
    var hash_val = window.location.hash; 
    if(hash_val=="#dienstleistungen"){ 
    $('html,body').animate({ 
     scrollTop:$("#dienstleistungen").offset().top-70 
    },2000); 
    }else if(hash_val=="#uberuns"){ 
    $('html,body').animate({ 
     scrollTop:$("#uberuns").offset().top-70 
    },2000); 
    } 
}); 
+0

Danke KTrivedi,我不打算讓頁面滾動到各種divs上點擊。我在頁腳中有一個鏈接,該鏈接需要在所有頁面上工作。目前只有當您在該特定div的頁面上纔有效,但如果您在不同頁面上鍊接被禁用。有趣的是,如果我檢查元素並單擊檢查器中的鏈接,它工作正常。 –