Skip to content

Commit aefe17b

Browse files
committed
优化JS代码细节 v1.0.1
1 parent 5cf1bf0 commit aefe17b

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# docsify-backTop
22

3-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://github.com/Sumsung524/docsify-backTop/blob/master/LICENSE)[![License: MIT](https://img.shields.io/badge/version-v1.0.0-green.svg?style=flat-square)](https://github.com/Sumsung524/docsify-backTop/releases)
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://github.com/Sumsung524/docsify-backTop/blob/master/LICENSE) [![License: MIT](https://img.shields.io/badge/version-v1.0.0-green.svg?style=flat-square)](https://github.com/Sumsung524/docsify-backTop/releases)
44

55
一个[docsify文档](https://docsify.js.org)的返回顶部插件,同时适用于其他需要添加回到顶部组件的所有页面。
66

77

88

99
演示地址:[docsify backTop Demo](https://xmq.plus/docs#/git/1.%E8%B5%B7%E6%AD%A5)
1010

11-
![screenshot](/screenshot.gif)
11+
![screenshot](screenshot.gif)
1212

1313
## 特征
1414

@@ -97,12 +97,12 @@ jsDelivr CDN引入或本地方式引入`docsify-backTop.min.js`文件:
9797

9898
## 参数说明
9999

100-
| 参数 | 参数取值 | 说明 |
101-
| ------- | ------------------------------------------------------------ | ---------------------------- |
102-
| size | 数值,必填 | 设置回到顶部组件大小 |
103-
| bottom | 数值,必填 | 设置回到顶部组件底部偏移距离 |
104-
| right | 数值,必填 | 设置回到顶部组件右侧偏移距离 |
105-
| logo | 字符、svg代码,内容使用单引号`''`包含,必填 | 设置回到顶部组件Logo |
100+
| 参数 | 参数取值 | 说明 |
101+
| ------- | ----------------------------------------------------------------------------------------- | ---------------------------- |
102+
| size | 数值,必填 | 设置回到顶部组件大小 |
103+
| bottom | 数值,必填 | 设置回到顶部组件底部偏移距离 |
104+
| right | 数值,必填 | 设置回到顶部组件右侧偏移距离 |
105+
| logo | 字符、svg代码,内容使用单引号`''`包含,必填 | 设置回到顶部组件Logo |
106106
| bgColor | 16进制颜色码(\#2096ff)、颜色(blue)等,内容使用单引号`''`包含,logo参数为svg图标时,不填。 | 设置回到顶部组件背景底色 |
107107

108108
回到顶部组件Logo中的svg代码可至[阿里巴巴矢量图库](https://www.iconfont.cn/)搜索“回到顶部”,选择自己喜欢的图标复制svg代码设置。

dist/docsify-backTop.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ window.addEventListener('DOMContentLoaded', function () {
33

44
// 4. 封装函数docsifyBackTopFn()
55
// 4.1 调用函数
6-
docsifyBackTopFn(docsifyBackTop.size, docsifyBackTop.bottom, docsifyBackTop.right, docsifyBackTop.logo, docsifyBackTop.bgColor);
6+
docsifyBackTopFn(docsifyBackTop);
77
// 4.2 封装函数
8-
function docsifyBackTopFn(backTopSize, backTopBottom, backTopRight, backTopLogo, backTopBGColor) {
8+
function docsifyBackTopFn(obj) {
99

1010
// 1. 创建元素
1111
// 1.1 获取body元素
1212
var body = document.body;
1313
// 1.2 创建回到顶部组件div
1414
var div = document.createElement('div');
1515
div.className = 'backTop';
16-
div.innerHTML = backTopLogo;
16+
div.innerHTML = obj.logo;
1717
body.appendChild(div);
1818
// 1.3 回到顶部CSS
1919
div.style.opacity = 0;
2020
div.style.position = 'fixed';
21-
div.style.bottom = backTopBottom + 'px';
22-
div.style.right = backTopRight + 'px';
23-
div.style.width = backTopSize + 'px';
21+
div.style.bottom = obj.bottom + 'px';
22+
div.style.right = obj.right + 'px';
23+
div.style.width = obj.size + 'px';
2424
div.style.height = div.style.width;
2525
div.style.textAlign = 'center';
2626
div.style.lineHeight = div.style.width;
27-
div.style.backgroundColor = backTopBGColor;
27+
div.style.backgroundColor = obj.bgColor;
2828
div.style.borderRadius = '50%';
2929
div.style.cursor = 'pointer';
3030
div.style.transition = 'opacity 0.5s';

dist/docsify-backTop.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
<body>
1818
<script>
1919
var docsifyBackTop = {
20-
size: 32, // 数值,组件大小,必填。
21-
bottom: 15, // 数值,组件底部偏移距离,必填。
22-
right: 15, // 数值,组件右侧偏移距离,必填。
20+
size: 32, // 数值,组件大小,必填。
21+
bottom: 15, // 数值,组件底部偏移距离,必填。
22+
right: 15, // 数值,组件右侧偏移距离,必填。
2323
// logo:字符串或svg矢量图代码,必填。
2424
logo: '<svg t="1662288563130" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3633" width="200" height="200"><path d="M513 103.7c-226.1 0-409.4 183.3-409.4 409.4S286.9 922.6 513 922.6s409.4-183.3 409.4-409.4S739.1 103.7 513 103.7z m153.5 364.7c-5.2 5.3-12.1 7.9-19 7.9s-13.8-2.6-19-7.9L545.1 385c0 0.4 0.1 0.7 0.1 1.1V705c0 11.1-5.7 20.9-14.4 26.6-4.7 4.2-10.9 6.7-17.7 6.7-6.8 0-13-2.5-17.7-6.7-8.7-5.7-14.4-15.5-14.4-26.6V386.1c0-0.4 0-0.7 0.1-1.1l-83.4 83.4c-10.5 10.5-27.5 10.5-38 0s-10.5-27.5 0-38L494 295.9c10.5-10.5 27.5-10.5 38 0l134.5 134.5c10.5 10.4 10.5 27.5 0 38z" fill="#2096ff" p-id="3634"></path></svg>',
25-
bgColor: '' // 背景颜色,#fff、pink等,logo为svg图标时,不填。
26-
};
25+
bgColor: '' // 背景颜色,#fff、pink等,logo为svg图标时,不填。
26+
}
2727
</script>
2828
</body>
2929

0 commit comments

Comments
 (0)