2016-07-26 72 views
8

下面是我用我的网页上的代码在Chrome中无法正常工作,锚<a>标签使用时#

<li><a href="/explore/#Sound">Sound</a></li> 

(在其中出现在所有页面上的菜单)

<a id="Sound"><a> 

(上我想链接到的页面)

我已经尝试添加内容到带有ID的标记。但只有在Chrome浏览器不会向下滚动到标签。这些锚点在IE & FF 中有效任何想法?

+0

您是否有链接到页面? – AshboDev

+0

https://dev.phonaudio.com/explore/#Sound –

+0

它需要认证。你可以做一个JSFiddle吗? – AshboDev

回答

26

原来,这是在特定的Chrome版本中的一个bug,发布解决办法的人谁需要它! :)

$(document).ready(function() { 
     var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); 
     if (window.location.hash && isChrome) { 
      setTimeout(function() { 
       var hash = window.location.hash; 
       window.location.hash = ""; 
       window.location.hash = hash; 
      }, 300); 
     } 
    }); 
+0

感谢队友,做好找到解决方案。最终到了那里! – AshboDev

+0

欢呼你的帮助,没有想到看铬...... –

+1

没问题!通常一个淘汰的过程会让你在那里! – AshboDev

-2
<html> 
    <body> 
    <li> 
     <a href="#Sound">Sound</a> 
    </li> 
    <a id="Sound" href="www.google.com">I AM CALLED</a> 
    </body> 
</html> 

以此作为你的代码就会调用锚标记值id声音

+0

这就是我已经拥有的,但没有工作,因为在铬特别是一个错误,谢谢:) –

3

发布的解决办法没有工作对我来说,这个搜索了几天之后终于不过的工作就像一个魅力,所以我想这是值得分享:

$(function() { 
     $('a[href*="#"]:not([href="#"])').click(function() { 
     if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { 
      var target = $(this.hash); 
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); 
      if (target.length) { 
      $('html, body').animate({ 
       scrollTop: target.offset().top 
      }, 1000); 
      return false; 
      } 
     } 
     }); 
    }); 
-1

只需改变呼叫您与外部的链接。

<a href="#nlink" class="external"> </a>