Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a bug of unicode hash #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
4 changes: 2 additions & 2 deletions smoothscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ var linkHandler = function(ev) {
if (!ev.defaultPrevented) {
ev.preventDefault();

if (location.hash !== this.hash) window.history.pushState(null, null, this.hash)
if (decodeURIComponent(location.hash) !== decodeURIComponent(this.hash)) window.history.pushState(null, null, decodeURIComponent(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
var node = document.getElementById(this.hash.substring(1))
var node = document.getElementById(decodeURIComponent(this.hash).substring(1))
if (!node) return; // Do not scroll to non-existing node

smoothScroll(node, 500, function (el) {
Expand Down
2 changes: 1 addition & 1 deletion smoothscroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 133 additions & 0 deletions test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!--<link href="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.css" rel="stylesheet"></head>-->
<style>
.link {
height: 100px;
background: #ef4567;
}
</style>
<body>
<script src="smoothscroll.js" type="text/javascript" charset="utf-8"></script>
<div id="顶部" style="height: 100px; background: #f5f2f9">顶部</div>
<div id="top" style="height: 100px; background: #f5f2f9">top</div>
<div id="aplayer"></div>
<div style="margin-top: 100px">
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link" style="background: deepskyblue">
<a href="#top" rel="">go top</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link" style="background: greenyellow">
<a href="#文本" rel="">go 文本</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div><div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
</div>
<p id="文本" style="margin: 50px 0">
文本
</p>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link" style="background: deepskyblue">
<a href="#top" rel="">go top</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<div class="link">
<a href="#顶部" rel="">go 顶部</a>
</div>
<script>
</script>
</body>
</html>