带有指向特定 div 的锚点的链接不起作用



所以我以前从未见过这个,它让我发疯。希望其他人以前遇到过这种情况,并且可以为我指出正确的方向。应该注意的是,该网站是在WP平台上构建的。

我有一个非常简单的链接设置: <a href="site.com/page-1/#div">

问题是,当我在任何页面上时,例如"site.com/page-2",当我单击链接时没有任何反应......没有触发任何事件。

如果我碰巧在"site.com/page-1"上并单击链接,它确实会滑动到相应的div。但是,同样,在任何其他页面上,链接根本不起作用。

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);
  } 
});

最新更新