Skip to content

Commit f369fe0

Browse files
committed
back to top start
1 parent e1b9732 commit f369fe0

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

_includes/backToTop.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="back-to-top">
2+
<a href="#">
3+
<i class="fa fa-arrow-up" aria-hidden="true"></i>
4+
</a>
5+
</div>

_includes/footer.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@
2929
</div>
3030
</footer>
3131
<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
32-
<script src="{{ " /js/main.js " | prepend: site.baseurl }}" charset="utf-8"></script>

_layouts/default.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
{{ content }}
1111

1212
{% include footer.html %}
13-
13+
{% include backToTop.html %}
14+
<script src="{{ " /js/main.js " | prepend: site.baseurl }}" charset="utf-8"></script>
1415
</body>
1516

1617
</html>

_sass/_backToTop.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.back-to-top {
2+
position: fixed;
3+
left: 50%;
4+
margin-left: 580px;
5+
bottom: 37px;
6+
background-color: #f8f8fd;
7+
visibility: hidden;
8+
opacity: 0;
9+
transition: 0.4s ease;
10+
box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.3), 0 0 30px rgba(10, 10, 0, 0.1) inset;
11+
a {
12+
display: block;
13+
background-color: #eee;
14+
width: 38px;
15+
height: 38px;
16+
line-height: 38px;
17+
text-align: center;
18+
font-size: 20px;
19+
color: #b4b4b4;
20+
}
21+
}
22+
.back-to-top-show{
23+
visibility: visible;
24+
opacity: 1;
25+
}

css/main.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"index",
5858
"demo",
5959
"footer",
60-
"scrollbar"
60+
"scrollbar",
61+
"backToTop"
6162
;
6263

6364
// 两个人在列车上相遇

js/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,21 @@
2727
})
2828
}
2929
}());
30+
31+
32+
//////////////////////////back to top////////////////////////////
33+
(function() {
34+
var backToTop = document.querySelector('.back-to-top')
35+
console.log(backToTop);
36+
window.onscroll = function() {
37+
38+
// 页面顶部滚进去的距离
39+
var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop)
40+
41+
if (scrollTop>200) {
42+
backToTop.classList.add('back-to-top-show')
43+
}else{
44+
backToTop.classList.remove('back-to-top-show')
45+
}
46+
}
47+
}());

0 commit comments

Comments
 (0)