bi-element-ui 0.1.50 → 0.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.browserslistrc +3 -3
- package/.eslintrc.js +287 -287
- package/.prettierrc +7 -7
- package/README.md +148 -148
- package/cypress.json +3 -3
- package/lib/bi-element-ui.common.js +24625 -24756
- package/lib/bi-element-ui.css +1 -1
- package/lib/bi-element-ui.umd.js +24625 -24756
- package/lib/bi-element-ui.umd.min.js +279 -2
- package/lib/static/img/swiperBg.png +0 -0
- package/package.json +57 -57
- package/src/App.vue +42 -42
- package/src/components/BiDatePicker/datePickerOption.js +229 -229
- package/src/components/BiDatePicker/index.vue +74 -74
- package/src/components/BiTable/columu.vue +104 -104
- package/src/components/BiTable/forced.js +76 -76
- package/src/components/BiTable/index.js +6 -6
- package/src/components/BiTable/render.vue +13 -13
- package/src/components/BiTable/table.vue +202 -202
- package/src/components/BiTableColumn/Group.vue +277 -277
- package/src/components/BiTableColumn/api.js +16 -16
- package/src/components/BiTableColumn/index.vue +614 -614
- package/src/components/BiTooltipIcon/index.vue +71 -71
- package/src/components/EditBtn.vue +15 -15
- package/src/components/FreeButton/index.vue +69 -69
- package/src/components/Pagination/index.vue +104 -104
- package/src/components/Pagination/scrollTo.js +69 -69
- package/src/main.js +18 -18
- package/src/router/index.js +39 -39
- package/src/store/index.js +11 -11
- package/src/table.js +463 -463
- package/src/views/Date.vue +132 -132
- package/src/views/Home.vue +330 -330
- package/src/views/Scene.vue +140 -140
- package/src/views/Table.vue +220 -220
- package/src/views/showData.vue +455 -455
- package/tests/e2e/.eslintrc.js +10 -10
- package/tests/e2e/plugins/index.js +25 -25
- package/tests/e2e/specs/test.js +8 -8
- package/tests/e2e/support/commands.js +25 -25
- package/tests/e2e/support/index.js +20 -20
- package/tests/unit/example.spec.js +13 -13
- package//345/211/215/347/253/257ui/346/240/267/345/274/217/350/247/204/350/214/203.md +101 -0
- package/dist/css/about.2c825c53.css +0 -1
- package/dist/css/chunk-vendors.8140bef9.css +0 -1
- package/dist/css/index.16a68369.css +0 -1
- package/dist/favicon.ico +0 -0
- package/dist/fonts/element-icons.535877f5.woff +0 -0
- package/dist/fonts/element-icons.732389de.ttf +0 -0
- package/dist/index.html +0 -1
- package/dist/js/about.78bcdce4.js +0 -2
- package/dist/js/chunk-vendors.dcba7b0e.js +0 -318
- package/dist/js/index.62a7fbd4.js +0 -2
- package/dist/static/img/swiperBg.png +0 -0
@@ -1,71 +1,71 @@
|
|
1
|
-
<!--
|
2
|
-
* @Author:gjh
|
3
|
-
* @Date: 2021-12-30 14:27:46
|
4
|
-
* @LastEditTime: 2021-12-30 16:15:22
|
5
|
-
* @LastEditors: Please set LastEditors
|
6
|
-
* @Description: 基于bi项目表格图标提示的需求
|
7
|
-
* @FilePath: \bi-element-ui\packages\TooltipIcon\src\index.vue
|
8
|
-
-->
|
9
|
-
<template>
|
10
|
-
<span>
|
11
|
-
<!-- 支持属性props的写法和插槽替换的写法 -->
|
12
|
-
<slot name="tip-label">
|
13
|
-
<span>{{ label }}</span>
|
14
|
-
</slot>
|
15
|
-
<el-tooltip
|
16
|
-
class="tooltip-icon"
|
17
|
-
:effect="effect"
|
18
|
-
:placement="placement"
|
19
|
-
v-bind="$attrs"
|
20
|
-
>
|
21
|
-
<template slot="content">
|
22
|
-
<slot name="tip-content">
|
23
|
-
<div v-html="content"></div>
|
24
|
-
</slot>
|
25
|
-
</template>
|
26
|
-
|
27
|
-
<slot name="tip-icon">
|
28
|
-
<span style="margin-left:5px">
|
29
|
-
<!-- 这里默认采用的是el-icon的图标 -->
|
30
|
-
<i :class="icon"></i>
|
31
|
-
</span>
|
32
|
-
</slot>
|
33
|
-
</el-tooltip>
|
34
|
-
</span>
|
35
|
-
|
36
|
-
</template>
|
37
|
-
|
38
|
-
<script>
|
39
|
-
export default {
|
40
|
-
name: 'BiTooltipIcon',
|
41
|
-
props: {
|
42
|
-
label: {
|
43
|
-
type: String,
|
44
|
-
default: '头部标题'
|
45
|
-
},
|
46
|
-
icon: {
|
47
|
-
type: String,
|
48
|
-
default: 'el-icon-warning-outline'
|
49
|
-
},
|
50
|
-
content: {
|
51
|
-
type: String,
|
52
|
-
default: '提示内容'
|
53
|
-
},
|
54
|
-
placement: {
|
55
|
-
type: String,
|
56
|
-
default: 'bottom'
|
57
|
-
},
|
58
|
-
effect: {
|
59
|
-
type: String,
|
60
|
-
default: 'dark'
|
61
|
-
}
|
62
|
-
},
|
63
|
-
data() {
|
64
|
-
return {}
|
65
|
-
}
|
66
|
-
}
|
67
|
-
</script>
|
68
|
-
|
69
|
-
<style>
|
70
|
-
</style>
|
71
|
-
|
1
|
+
<!--
|
2
|
+
* @Author:gjh
|
3
|
+
* @Date: 2021-12-30 14:27:46
|
4
|
+
* @LastEditTime: 2021-12-30 16:15:22
|
5
|
+
* @LastEditors: Please set LastEditors
|
6
|
+
* @Description: 基于bi项目表格图标提示的需求
|
7
|
+
* @FilePath: \bi-element-ui\packages\TooltipIcon\src\index.vue
|
8
|
+
-->
|
9
|
+
<template>
|
10
|
+
<span>
|
11
|
+
<!-- 支持属性props的写法和插槽替换的写法 -->
|
12
|
+
<slot name="tip-label">
|
13
|
+
<span>{{ label }}</span>
|
14
|
+
</slot>
|
15
|
+
<el-tooltip
|
16
|
+
class="tooltip-icon"
|
17
|
+
:effect="effect"
|
18
|
+
:placement="placement"
|
19
|
+
v-bind="$attrs"
|
20
|
+
>
|
21
|
+
<template slot="content">
|
22
|
+
<slot name="tip-content">
|
23
|
+
<div v-html="content"></div>
|
24
|
+
</slot>
|
25
|
+
</template>
|
26
|
+
|
27
|
+
<slot name="tip-icon">
|
28
|
+
<span style="margin-left:5px">
|
29
|
+
<!-- 这里默认采用的是el-icon的图标 -->
|
30
|
+
<i :class="icon"></i>
|
31
|
+
</span>
|
32
|
+
</slot>
|
33
|
+
</el-tooltip>
|
34
|
+
</span>
|
35
|
+
|
36
|
+
</template>
|
37
|
+
|
38
|
+
<script>
|
39
|
+
export default {
|
40
|
+
name: 'BiTooltipIcon',
|
41
|
+
props: {
|
42
|
+
label: {
|
43
|
+
type: String,
|
44
|
+
default: '头部标题'
|
45
|
+
},
|
46
|
+
icon: {
|
47
|
+
type: String,
|
48
|
+
default: 'el-icon-warning-outline'
|
49
|
+
},
|
50
|
+
content: {
|
51
|
+
type: String,
|
52
|
+
default: '提示内容'
|
53
|
+
},
|
54
|
+
placement: {
|
55
|
+
type: String,
|
56
|
+
default: 'bottom'
|
57
|
+
},
|
58
|
+
effect: {
|
59
|
+
type: String,
|
60
|
+
default: 'dark'
|
61
|
+
}
|
62
|
+
},
|
63
|
+
data() {
|
64
|
+
return {}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
</script>
|
68
|
+
|
69
|
+
<style>
|
70
|
+
</style>
|
71
|
+
|
@@ -1,15 +1,15 @@
|
|
1
|
-
<template>
|
2
|
-
<el-button size="mini" @click="todo">编辑</el-button>
|
3
|
-
</template>
|
4
|
-
|
5
|
-
<script>
|
6
|
-
export default {
|
7
|
-
props: ['row', 'column'],
|
8
|
-
|
9
|
-
methods: {
|
10
|
-
todo() {
|
11
|
-
this.$emit('row-edit', this.row)
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
15
|
-
</script>
|
1
|
+
<template>
|
2
|
+
<el-button size="mini" @click="todo">编辑</el-button>
|
3
|
+
</template>
|
4
|
+
|
5
|
+
<script>
|
6
|
+
export default {
|
7
|
+
props: ['row', 'column'],
|
8
|
+
|
9
|
+
methods: {
|
10
|
+
todo() {
|
11
|
+
this.$emit('row-edit', this.row)
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
</script>
|
@@ -1,69 +1,69 @@
|
|
1
|
-
<template>
|
2
|
-
<div class="free-button">
|
3
|
-
<slot></slot>
|
4
|
-
<el-button
|
5
|
-
type="primary"
|
6
|
-
icon="el-icon-search"
|
7
|
-
@click="search"
|
8
|
-
>查询</el-button>
|
9
|
-
<el-button
|
10
|
-
type="primary"
|
11
|
-
icon="el-icon-edit"
|
12
|
-
>编辑</el-button>
|
13
|
-
<el-button
|
14
|
-
type="success"
|
15
|
-
icon="el-icon-plus"
|
16
|
-
>新增</el-button>
|
17
|
-
<el-button
|
18
|
-
type="info"
|
19
|
-
icon="el-icon-download"
|
20
|
-
>导出</el-button>
|
21
|
-
<el-button
|
22
|
-
type="warning"
|
23
|
-
icon="el-icon-upload2"
|
24
|
-
>导入</el-button>
|
25
|
-
<el-button
|
26
|
-
type="danger"
|
27
|
-
icon="el-icon-delete"
|
28
|
-
>删除</el-button>
|
29
|
-
</div>
|
30
|
-
</template>
|
31
|
-
|
32
|
-
<script>
|
33
|
-
const EVENT_NAMES = ['search', 'add', 'edit', 'delete', 'import', 'exprot']
|
34
|
-
|
35
|
-
const methods = {}
|
36
|
-
// const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1)
|
37
|
-
|
38
|
-
EVENT_NAMES.forEach((name) => {
|
39
|
-
methods[name] = function () {
|
40
|
-
this.$emit(name)
|
41
|
-
}
|
42
|
-
})
|
43
|
-
|
44
|
-
export default {
|
45
|
-
name: 'FreeButton',
|
46
|
-
props: {
|
47
|
-
btnsCol: {
|
48
|
-
type: Array,
|
49
|
-
default: () => {
|
50
|
-
return [
|
51
|
-
{ type: 'search', label: '查询', event: 'onSearch' },
|
52
|
-
{ type: 'delete', label: '删除', event: 'onDelete' }
|
53
|
-
]
|
54
|
-
}
|
55
|
-
},
|
56
|
-
btnsProps: Object
|
57
|
-
},
|
58
|
-
methods: {
|
59
|
-
bindEvents(name) {
|
60
|
-
this.$emit(name)
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
</script>
|
65
|
-
<style>
|
66
|
-
.free-button {
|
67
|
-
margin: 10px 0;
|
68
|
-
}
|
69
|
-
</style>
|
1
|
+
<template>
|
2
|
+
<div class="free-button">
|
3
|
+
<slot></slot>
|
4
|
+
<el-button
|
5
|
+
type="primary"
|
6
|
+
icon="el-icon-search"
|
7
|
+
@click="search"
|
8
|
+
>查询</el-button>
|
9
|
+
<el-button
|
10
|
+
type="primary"
|
11
|
+
icon="el-icon-edit"
|
12
|
+
>编辑</el-button>
|
13
|
+
<el-button
|
14
|
+
type="success"
|
15
|
+
icon="el-icon-plus"
|
16
|
+
>新增</el-button>
|
17
|
+
<el-button
|
18
|
+
type="info"
|
19
|
+
icon="el-icon-download"
|
20
|
+
>导出</el-button>
|
21
|
+
<el-button
|
22
|
+
type="warning"
|
23
|
+
icon="el-icon-upload2"
|
24
|
+
>导入</el-button>
|
25
|
+
<el-button
|
26
|
+
type="danger"
|
27
|
+
icon="el-icon-delete"
|
28
|
+
>删除</el-button>
|
29
|
+
</div>
|
30
|
+
</template>
|
31
|
+
|
32
|
+
<script>
|
33
|
+
const EVENT_NAMES = ['search', 'add', 'edit', 'delete', 'import', 'exprot']
|
34
|
+
|
35
|
+
const methods = {}
|
36
|
+
// const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1)
|
37
|
+
|
38
|
+
EVENT_NAMES.forEach((name) => {
|
39
|
+
methods[name] = function () {
|
40
|
+
this.$emit(name)
|
41
|
+
}
|
42
|
+
})
|
43
|
+
|
44
|
+
export default {
|
45
|
+
name: 'FreeButton',
|
46
|
+
props: {
|
47
|
+
btnsCol: {
|
48
|
+
type: Array,
|
49
|
+
default: () => {
|
50
|
+
return [
|
51
|
+
{ type: 'search', label: '查询', event: 'onSearch' },
|
52
|
+
{ type: 'delete', label: '删除', event: 'onDelete' }
|
53
|
+
]
|
54
|
+
}
|
55
|
+
},
|
56
|
+
btnsProps: Object
|
57
|
+
},
|
58
|
+
methods: {
|
59
|
+
bindEvents(name) {
|
60
|
+
this.$emit(name)
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
</script>
|
65
|
+
<style>
|
66
|
+
.free-button {
|
67
|
+
margin: 10px 0;
|
68
|
+
}
|
69
|
+
</style>
|
@@ -1,104 +1,104 @@
|
|
1
|
-
<template>
|
2
|
-
<div
|
3
|
-
:class="{ hidden: hidden }"
|
4
|
-
class="pagination-container"
|
5
|
-
>
|
6
|
-
<el-pagination
|
7
|
-
:background="background"
|
8
|
-
:current-page.sync="currentPage"
|
9
|
-
:page-size.sync="pageSize"
|
10
|
-
:layout="layout"
|
11
|
-
:page-sizes="pageSizes"
|
12
|
-
:total="total"
|
13
|
-
v-bind="$attrs"
|
14
|
-
@size-change="handleSizeChange"
|
15
|
-
@current-change="handleCurrentChange"
|
16
|
-
/>
|
17
|
-
</div>
|
18
|
-
</template>
|
19
|
-
|
20
|
-
<script>
|
21
|
-
import { scrollTo } from './scrollTo'
|
22
|
-
|
23
|
-
export default {
|
24
|
-
name: 'Pagination',
|
25
|
-
props: {
|
26
|
-
total: {
|
27
|
-
required: true,
|
28
|
-
type: Number
|
29
|
-
},
|
30
|
-
page: {
|
31
|
-
type: Number,
|
32
|
-
default: 1
|
33
|
-
},
|
34
|
-
limit: {
|
35
|
-
type: Number,
|
36
|
-
default: 20
|
37
|
-
},
|
38
|
-
pageSizes: {
|
39
|
-
type: Array,
|
40
|
-
default() {
|
41
|
-
return [10, 20, 30, 50]
|
42
|
-
}
|
43
|
-
},
|
44
|
-
layout: {
|
45
|
-
type: String,
|
46
|
-
default: 'total, sizes, prev, pager, next, jumper'
|
47
|
-
},
|
48
|
-
background: {
|
49
|
-
type: Boolean,
|
50
|
-
default: true
|
51
|
-
},
|
52
|
-
autoScroll: {
|
53
|
-
type: Boolean,
|
54
|
-
default: true
|
55
|
-
},
|
56
|
-
hidden: {
|
57
|
-
type: Boolean,
|
58
|
-
default: false
|
59
|
-
}
|
60
|
-
},
|
61
|
-
computed: {
|
62
|
-
currentPage: {
|
63
|
-
get() {
|
64
|
-
return this.page
|
65
|
-
},
|
66
|
-
set(val) {
|
67
|
-
this.$emit('update:page', val)
|
68
|
-
}
|
69
|
-
},
|
70
|
-
pageSize: {
|
71
|
-
get() {
|
72
|
-
return this.limit
|
73
|
-
},
|
74
|
-
set(val) {
|
75
|
-
this.$emit('update:limit', val)
|
76
|
-
}
|
77
|
-
}
|
78
|
-
},
|
79
|
-
methods: {
|
80
|
-
handleSizeChange(val) {
|
81
|
-
this.$emit('pagination', { page: this.currentPage, limit: val })
|
82
|
-
if (this.autoScroll) {
|
83
|
-
scrollTo(0, 800)
|
84
|
-
}
|
85
|
-
},
|
86
|
-
handleCurrentChange(val) {
|
87
|
-
this.$emit('pagination', { page: val, limit: this.pageSize })
|
88
|
-
if (this.autoScroll) {
|
89
|
-
scrollTo(0, 800)
|
90
|
-
}
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
</script>
|
95
|
-
|
96
|
-
<style scoped>
|
97
|
-
.pagination-container {
|
98
|
-
background: #fff;
|
99
|
-
padding: 20px 16px;
|
100
|
-
}
|
101
|
-
.pagination-container.hidden {
|
102
|
-
display: none;
|
103
|
-
}
|
104
|
-
</style>
|
1
|
+
<template>
|
2
|
+
<div
|
3
|
+
:class="{ hidden: hidden }"
|
4
|
+
class="pagination-container"
|
5
|
+
>
|
6
|
+
<el-pagination
|
7
|
+
:background="background"
|
8
|
+
:current-page.sync="currentPage"
|
9
|
+
:page-size.sync="pageSize"
|
10
|
+
:layout="layout"
|
11
|
+
:page-sizes="pageSizes"
|
12
|
+
:total="total"
|
13
|
+
v-bind="$attrs"
|
14
|
+
@size-change="handleSizeChange"
|
15
|
+
@current-change="handleCurrentChange"
|
16
|
+
/>
|
17
|
+
</div>
|
18
|
+
</template>
|
19
|
+
|
20
|
+
<script>
|
21
|
+
import { scrollTo } from './scrollTo'
|
22
|
+
|
23
|
+
export default {
|
24
|
+
name: 'Pagination',
|
25
|
+
props: {
|
26
|
+
total: {
|
27
|
+
required: true,
|
28
|
+
type: Number
|
29
|
+
},
|
30
|
+
page: {
|
31
|
+
type: Number,
|
32
|
+
default: 1
|
33
|
+
},
|
34
|
+
limit: {
|
35
|
+
type: Number,
|
36
|
+
default: 20
|
37
|
+
},
|
38
|
+
pageSizes: {
|
39
|
+
type: Array,
|
40
|
+
default() {
|
41
|
+
return [10, 20, 30, 50]
|
42
|
+
}
|
43
|
+
},
|
44
|
+
layout: {
|
45
|
+
type: String,
|
46
|
+
default: 'total, sizes, prev, pager, next, jumper'
|
47
|
+
},
|
48
|
+
background: {
|
49
|
+
type: Boolean,
|
50
|
+
default: true
|
51
|
+
},
|
52
|
+
autoScroll: {
|
53
|
+
type: Boolean,
|
54
|
+
default: true
|
55
|
+
},
|
56
|
+
hidden: {
|
57
|
+
type: Boolean,
|
58
|
+
default: false
|
59
|
+
}
|
60
|
+
},
|
61
|
+
computed: {
|
62
|
+
currentPage: {
|
63
|
+
get() {
|
64
|
+
return this.page
|
65
|
+
},
|
66
|
+
set(val) {
|
67
|
+
this.$emit('update:page', val)
|
68
|
+
}
|
69
|
+
},
|
70
|
+
pageSize: {
|
71
|
+
get() {
|
72
|
+
return this.limit
|
73
|
+
},
|
74
|
+
set(val) {
|
75
|
+
this.$emit('update:limit', val)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
},
|
79
|
+
methods: {
|
80
|
+
handleSizeChange(val) {
|
81
|
+
this.$emit('pagination', { page: this.currentPage, limit: val })
|
82
|
+
if (this.autoScroll) {
|
83
|
+
scrollTo(0, 800)
|
84
|
+
}
|
85
|
+
},
|
86
|
+
handleCurrentChange(val) {
|
87
|
+
this.$emit('pagination', { page: val, limit: this.pageSize })
|
88
|
+
if (this.autoScroll) {
|
89
|
+
scrollTo(0, 800)
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
</script>
|
95
|
+
|
96
|
+
<style scoped>
|
97
|
+
.pagination-container {
|
98
|
+
background: #fff;
|
99
|
+
padding: 20px 16px;
|
100
|
+
}
|
101
|
+
.pagination-container.hidden {
|
102
|
+
display: none;
|
103
|
+
}
|
104
|
+
</style>
|
@@ -1,69 +1,69 @@
|
|
1
|
-
Math.easeInOutQuad = function(t, b, c, d) {
|
2
|
-
t /= d / 2
|
3
|
-
if (t < 1) {
|
4
|
-
return (c / 2) * t * t + b
|
5
|
-
}
|
6
|
-
t--
|
7
|
-
return (-c / 2) * (t * (t - 2) - 1) + b
|
8
|
-
}
|
9
|
-
|
10
|
-
// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
|
11
|
-
var requestAnimFrame = (function() {
|
12
|
-
return (
|
13
|
-
window.requestAnimationFrame ||
|
14
|
-
window.webkitRequestAnimationFrame ||
|
15
|
-
window.mozRequestAnimationFrame ||
|
16
|
-
function(callback) {
|
17
|
-
window.setTimeout(callback, 1000 / 60)
|
18
|
-
}
|
19
|
-
)
|
20
|
-
})()
|
21
|
-
|
22
|
-
/**
|
23
|
-
* Because it's so fucking difficult to detect the scrolling element, just move them all
|
24
|
-
* @param {number} amount
|
25
|
-
*/
|
26
|
-
function move(amount) {
|
27
|
-
document.documentElement.scrollTop = amount
|
28
|
-
document.body.parentNode.scrollTop = amount
|
29
|
-
document.body.scrollTop = amount
|
30
|
-
}
|
31
|
-
|
32
|
-
function position() {
|
33
|
-
return (
|
34
|
-
document.documentElement.scrollTop ||
|
35
|
-
document.body.parentNode.scrollTop ||
|
36
|
-
document.body.scrollTop
|
37
|
-
)
|
38
|
-
}
|
39
|
-
|
40
|
-
/**
|
41
|
-
* @param {number} to
|
42
|
-
* @param {number} duration
|
43
|
-
* @param {Function} callback
|
44
|
-
*/
|
45
|
-
export function scrollTo(to, duration, callback) {
|
46
|
-
const start = position()
|
47
|
-
const change = to - start
|
48
|
-
const increment = 20
|
49
|
-
let currentTime = 0
|
50
|
-
duration = typeof duration === 'undefined' ? 500 : duration
|
51
|
-
var animateScroll = function() {
|
52
|
-
// increment the time
|
53
|
-
currentTime += increment
|
54
|
-
// find the value with the quadratic in-out easing function
|
55
|
-
var val = Math.easeInOutQuad(currentTime, start, change, duration)
|
56
|
-
// move the document.body
|
57
|
-
move(val)
|
58
|
-
// do the animation unless its over
|
59
|
-
if (currentTime < duration) {
|
60
|
-
requestAnimFrame(animateScroll)
|
61
|
-
} else {
|
62
|
-
if (callback && typeof callback === 'function') {
|
63
|
-
// the animation is done so lets callback
|
64
|
-
callback()
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
68
|
-
animateScroll()
|
69
|
-
}
|
1
|
+
Math.easeInOutQuad = function(t, b, c, d) {
|
2
|
+
t /= d / 2
|
3
|
+
if (t < 1) {
|
4
|
+
return (c / 2) * t * t + b
|
5
|
+
}
|
6
|
+
t--
|
7
|
+
return (-c / 2) * (t * (t - 2) - 1) + b
|
8
|
+
}
|
9
|
+
|
10
|
+
// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
|
11
|
+
var requestAnimFrame = (function() {
|
12
|
+
return (
|
13
|
+
window.requestAnimationFrame ||
|
14
|
+
window.webkitRequestAnimationFrame ||
|
15
|
+
window.mozRequestAnimationFrame ||
|
16
|
+
function(callback) {
|
17
|
+
window.setTimeout(callback, 1000 / 60)
|
18
|
+
}
|
19
|
+
)
|
20
|
+
})()
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Because it's so fucking difficult to detect the scrolling element, just move them all
|
24
|
+
* @param {number} amount
|
25
|
+
*/
|
26
|
+
function move(amount) {
|
27
|
+
document.documentElement.scrollTop = amount
|
28
|
+
document.body.parentNode.scrollTop = amount
|
29
|
+
document.body.scrollTop = amount
|
30
|
+
}
|
31
|
+
|
32
|
+
function position() {
|
33
|
+
return (
|
34
|
+
document.documentElement.scrollTop ||
|
35
|
+
document.body.parentNode.scrollTop ||
|
36
|
+
document.body.scrollTop
|
37
|
+
)
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @param {number} to
|
42
|
+
* @param {number} duration
|
43
|
+
* @param {Function} callback
|
44
|
+
*/
|
45
|
+
export function scrollTo(to, duration, callback) {
|
46
|
+
const start = position()
|
47
|
+
const change = to - start
|
48
|
+
const increment = 20
|
49
|
+
let currentTime = 0
|
50
|
+
duration = typeof duration === 'undefined' ? 500 : duration
|
51
|
+
var animateScroll = function() {
|
52
|
+
// increment the time
|
53
|
+
currentTime += increment
|
54
|
+
// find the value with the quadratic in-out easing function
|
55
|
+
var val = Math.easeInOutQuad(currentTime, start, change, duration)
|
56
|
+
// move the document.body
|
57
|
+
move(val)
|
58
|
+
// do the animation unless its over
|
59
|
+
if (currentTime < duration) {
|
60
|
+
requestAnimFrame(animateScroll)
|
61
|
+
} else {
|
62
|
+
if (callback && typeof callback === 'function') {
|
63
|
+
// the animation is done so lets callback
|
64
|
+
callback()
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
animateScroll()
|
69
|
+
}
|