Skip to content

Commit 9bc1c27

Browse files
committed
add animation of scroll
1 parent f369fe0 commit 9bc1c27

File tree

8 files changed

+15
-11
lines changed

8 files changed

+15
-11
lines changed

_includes/backToTop.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="back-to-top">
2-
<a href="#">
2+
<a href="#top" class="scroll">
33
<i class="fa fa-arrow-up" aria-hidden="true"></i>
44
</a>
55
</div>

_includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<header>
1+
<header id="top">
22
<div class="wrapper">
33
<a href="{{ site.baseurl }}/" class="brand">{{ site.title }}</a>
44
<small>{{site.brief-intro}}</small>

_layouts/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
{% include footer.html %}
1313
{% include backToTop.html %}
1414
<script src="{{ " /js/main.js " | prepend: site.baseurl }}" charset="utf-8"></script>
15+
<script src="{{ " /js/scroll.min.js " | prepend: site.baseurl }}" charset="utf-8"></script>
1516
</body>
1617

1718
</html>

_layouts/post.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,4 @@ <h2 id="comments">Comments</h2>
9797
}
9898
}());
9999
</script>
100-
<script src="{{ "/js/scroll.min.js " | prepend: site.baseurl }}" charset="utf-8"></script>
101100
<script src="{{ "/js/pageContent.js " | prepend: site.baseurl }}" charset="utf-8"></script>

js/main.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,23 @@
3232
//////////////////////////back to top////////////////////////////
3333
(function() {
3434
var backToTop = document.querySelector('.back-to-top')
35-
console.log(backToTop);
36-
window.onscroll = function() {
35+
var backToTopA = document.querySelector('.back-to-top a')
36+
// console.log(backToTop);
37+
window.addEventListener('scroll',function () {
38+
3739

3840
// 页面顶部滚进去的距离
3941
var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop)
4042

41-
if (scrollTop>200) {
43+
if (scrollTop > 200) {
4244
backToTop.classList.add('back-to-top-show')
43-
}else{
45+
} else {
4446
backToTop.classList.remove('back-to-top-show')
4547
}
46-
}
48+
})
49+
50+
// backToTopA.addEventListener('click',function (e) {
51+
// e.preventDefault()
52+
// window.scrollTo(0,0)
53+
// })
4754
}());

page/0archives.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,4 @@ <h2 id="y{{ post.date | date: '%Y' }}">{{ post.date | date: '%Y' }}</h2>
6565
</div>
6666
</div>
6767
</div>
68-
<script src="{{ "/js/scroll.min.js " | prepend: site.baseurl }}" charset="utf-8"></script>
6968
<script src="{{ "/js/pageContent.js " | prepend: site.baseurl }}" charset="utf-8"></script>

page/1category.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,4 @@ <h2 id="{{category | first}}">{{category | first}}</h2>
5555
</div>
5656
</div>
5757
</div>
58-
<script src="{{ "/js/scroll.min.js " | prepend: site.baseurl }}" charset="utf-8"></script>
5958
<script src="{{ "/js/pageContent.js " | prepend: site.baseurl }}" charset="utf-8"></script>

page/2tags.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,4 @@ <h2 id="{{ tag }}">{{ tag }}</h2>
5959
</div>
6060
</div>
6161
</div>
62-
<script src="{{ "/js/scroll.min.js " | prepend: site.baseurl }}" charset="utf-8"></script>
6362
<script src="{{ "/js/pageContent.js " | prepend: site.baseurl }}" charset="utf-8"></script>

0 commit comments

Comments
 (0)