我有以下JS,但我不希望URL使用散列更新,我如何防止这种情况?
我希望的scrollTop工作时,两个相同的页面锚链接和链接到一个不同的页面上的ID,这是目前工作正常。
var jump=function(e)
{
if (e){
e.preventDefault();
var target = $(this).attr("href");
} else {
var target = location.hash;
}
$('html,body').animate(
{
scrollTop: $(target).offset().top
}, 2000, function()
{
location.hash = target;
});
}
$('html, body').hide();
$(document).ready(function()
{
$('a[href^=#]').bind("click", jump);
if (location.hash){
setTimeout(function(){
$('html, body').scrollTop(0).show();
jump();
}, 0);
}else{
$('html, body').show();
}
});发布于 2014-04-30 19:14:14
将window.location.hash = '‘添加到您的跳转函数:
... //previous code
window.location.hash = ''
... 这将从导航栏中的url中删除散列。
:另外,将'return false‘添加到跳转函数的末尾。这应该会阻止事件传播和更改地址栏中的哈希
https://stackoverflow.com/questions/23386350
复制相似问题