--- layout: post # 使用的布局(不需要改) title: Jekyll添加返回顶部按钮 # 标题 subtitle: 一键返回顶部 #副标题 date: 2019-10-04 # 时间 author: Duter2016 # 作者 header-img: img/post-bg-kuaidi.jpg #这篇文章标题背景图片 header-mask: "0.1" # 博文页面上端的背景图片的亮度,数值越大越黑暗 catalog: true # 开启catalog,将在博文侧边展示博文的结构 music-id: # 网易云音乐单曲嵌入 music-idfull: # 网易云音乐歌单嵌入 tags: #标签 - Blog --- 只需两步就可以在页面添加一个固定的返回顶部按钮,这里没有加JS代码,没什么漂亮的效果,只是功能的实现。 ### 添加返回按钮块 将以下代码添加到博文采用的布局html文件的最后,比如我的是footer.html中,网站全局均可使用。 ```
TOP
``` ### 添加按钮的css样式 把下面的css样式粘入你的Jekyll使用的css表中,可以按照自己喜欢修改样式即可。 ```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; /* 文字颜色 */ } ``` #### 参考文章: [《Jekyll博文内链和返回顶部按钮》](https://www.smslit.top/2015/10/28/backToTop-Jekyll/)