【发布时间】:2015-08-13 14:42:34
【问题描述】:
我在使用 plagin (smoothscroll.js) 的单页滚动模板中遇到问题 用户单击链接后,我尝试从 url 中删除哈希,但不幸的是我不能这样做。例如
http://localhost/template/#section2
我如何从网址中删除#section2
这里是代码
var linkHandler = function(ev) {
ev.preventDefault();
if (location.hash !== this.hash) window.history.pushState(null, null, this.hash);
// using the history api to solve issue #1 - back doesn't work
// most browser don't update :target when the history api is used:
// THIS IS A BUG FROM THE BROWSERS.
// change the scrolling duration in this call
smoothScroll(document.getElementById(this.hash.substring(1)), 1000, function(el) {
location.replace('#' + el.id);
// this will cause the :target to be activated.
});
}
【问题讨论】:
-
谁能帮帮我?