layout | title | subtitle | date | author | header-img | header-mask | catalog | music-id | music-idfull | tags | |
---|---|---|---|---|---|---|---|---|---|---|---|
post |
Jekyll添加返回顶部按钮 |
一键返回顶部 |
2019-10-04 |
Duter2016 |
img/post-bg-kuaidi.jpg |
0.1 |
true |
|
只需两步就可以在页面添加一个固定的返回顶部按钮,这里没有加JS代码,没什么漂亮的效果,只是功能的实现。
将以下代码添加到博文采用的布局html文件的最后,比如我的是footer.html中,网站全局均可使用。
<div id="backtop">
<a href="#">TOP</a>
</div>
把下面的css样式粘入你的Jekyll使用的css表中,可以按照自己喜欢修改样式即可。
#backtop a { /* back to top button */
text-align: center;
line-height: 50px;
font-size: 16px;
width:50px;
height: 50px;
position: fixed;
bottom: 10px; /* 小按钮到浏览器底边的距离 */
right: 60px; /* 小按钮到浏览器右边框的距离 */
color: rgb(64,120,192); /* 小按钮中文字的颜色 */
z-index: 1000;
background: #fff; /* 小按钮底色 */
padding: auto; /* 小按钮中文字到按钮边缘的距离 */
border-radius: 50px; /* 小按钮圆角的弯曲程度(半径)*/
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
font-weight: bold; /* 小按钮中文字的粗细 */
text-decoration: none !important;
box-shadow:0 1px 2px rgba(0,0,0,.15), 0 1px 0 #ffffff inset;
}
#backtop a:hover { /* 小按钮上有鼠标悬停时 */
background: rgba(64,120,192,0.8); /* 小按钮的底色 */
color: #fff; /* 文字颜色 */
}