下面是我用我的网页上的代码在Chrome中无法正常工作,锚<a>标签使用时#
<li><a href="/explore/#Sound">Sound</a></li>
(在其中出现在所有页面上的菜单)
<a id="Sound"><a>
(上我想链接到的页面)
我已经尝试添加内容到带有ID的标记。但只有在Chrome浏览器不会向下滚动到标签。这些锚点在IE & FF 中有效任何想法?
下面是我用我的网页上的代码在Chrome中无法正常工作,锚<a>标签使用时#
<li><a href="/explore/#Sound">Sound</a></li>
(在其中出现在所有页面上的菜单)
<a id="Sound"><a>
(上我想链接到的页面)
我已经尝试添加内容到带有ID的标记。但只有在Chrome浏览器不会向下滚动到标签。这些锚点在IE & FF 中有效任何想法?
原来,这是在特定的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);
}
});
<html>
<body>
<li>
<a href="#Sound">Sound</a>
</li>
<a id="Sound" href="www.google.com">I AM CALLED</a>
</body>
</html>
以此作为你的代码就会调用锚标记值id声音
这就是我已经拥有的,但没有工作,因为在铬特别是一个错误,谢谢:) –
发布的解决办法没有工作对我来说,这个搜索了几天之后终于不过的工作就像一个魅力,所以我想这是值得分享:
$(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;
}
}
});
});
只需改变呼叫您与外部的链接。
<a href="#nlink" class="external"> </a>
您是否有链接到页面? – AshboDev
https://dev.phonaudio.com/explore/#Sound –
它需要认证。你可以做一个JSFiddle吗? – AshboDev