kui-vue 3.2.3-rc1 → 3.2.3-rc3
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/components/affix/affix.jsx +23 -75
- package/components/affix/demo/container.md +14 -7
- package/dist/k-ui.js +2 -2
- package/package.json +3 -2
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import resize from '../_tool/resize'
|
|
3
3
|
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
top = element.offsetTop - element.parentElement.offsetTop
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
top, height, width, scrollTop,
|
|
15
|
-
targetTop: targetRect.top,
|
|
16
|
-
targetHeight: targetRect.height,
|
|
17
|
-
targetInnerHeight: target.innerHeight || target.clientHeight
|
|
18
|
-
}
|
|
19
|
-
}
|
|
4
|
+
// function getStyle(el, attr) {
|
|
5
|
+
// if (el.currentStyle) {
|
|
6
|
+
// return el.currentStyle[attr];
|
|
7
|
+
// } else {
|
|
8
|
+
// return getComputedStyle(el, false)[attr];
|
|
9
|
+
// }
|
|
10
|
+
// }
|
|
20
11
|
|
|
21
12
|
export default {
|
|
22
13
|
name: 'Affix',
|
|
@@ -31,10 +22,7 @@ export default {
|
|
|
31
22
|
fixed: false,
|
|
32
23
|
width: 0,
|
|
33
24
|
height: 0,
|
|
34
|
-
|
|
35
|
-
offsetModeOfBottom: false,
|
|
36
|
-
offsetTopValue: this.offsetTop,
|
|
37
|
-
offsetBottomValue: this.offsetBottom
|
|
25
|
+
offsetTopValue: 0,
|
|
38
26
|
}
|
|
39
27
|
},
|
|
40
28
|
|
|
@@ -42,64 +30,29 @@ export default {
|
|
|
42
30
|
let target = this.target()
|
|
43
31
|
if (target) {
|
|
44
32
|
target.addEventListener('scroll', e => {
|
|
45
|
-
// console.log(e)
|
|
46
33
|
this.updatePosition(e)
|
|
47
|
-
// console.log(e)
|
|
48
34
|
})
|
|
49
35
|
}
|
|
50
|
-
// this.updatePosition(target)
|
|
51
36
|
},
|
|
52
37
|
methods: {
|
|
53
38
|
updatePosition(e) {
|
|
54
39
|
let { offsetBottom, offsetTop, $refs } = this
|
|
55
|
-
if (!$refs.blob) return;
|
|
56
|
-
|
|
57
40
|
let target = this.target()
|
|
41
|
+
if (!$refs.blob || !target) return;
|
|
58
42
|
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
offsetTop = target === window ? offsetTop : scrollTop
|
|
62
|
-
if (this.fixed) {
|
|
43
|
+
let rect = $refs.blob.getBoundingClientRect();
|
|
44
|
+
let rect2 = target != window && target != document ? target.getBoundingClientRect() : { top: 0, bottom: document.documentElement.clientHeight }
|
|
63
45
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
if (target !== window && top !== targetTop) {
|
|
76
|
-
this.offsetTopValue = targetTop
|
|
77
|
-
}
|
|
78
|
-
if (!this.fixed) {
|
|
79
|
-
this.fixed = false
|
|
80
|
-
this.$emit('change', false)
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
if (typeof offsetBottom != undefined && offsetBottom >= 0) {
|
|
84
|
-
//fixedBottom
|
|
85
|
-
if (0 <= top + height + offsetBottom - targetInnerHeight) {
|
|
86
|
-
this.offsetModeOfBottom = true
|
|
87
|
-
this.fixed = true
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
if (top <= offsetTop) { //fixedTop
|
|
91
|
-
this.fixed = true
|
|
92
|
-
this.offsetModeOfTop = true
|
|
93
|
-
if (target !== window) {
|
|
94
|
-
this.offsetTopValue = targetTop
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (this.fixed) {
|
|
99
|
-
this.$emit('change', true)
|
|
100
|
-
this.width = width
|
|
101
|
-
this.height = height
|
|
102
|
-
}
|
|
46
|
+
let hasbottom = typeof offsetBottom == 'number' && offsetBottom >= 0
|
|
47
|
+
let fx = hasbottom ? rect2.bottom - rect.bottom >= offsetBottom : rect.top - rect2.top <= offsetTop
|
|
48
|
+
if (!fx) {
|
|
49
|
+
this.offsetTopValue = rect.top
|
|
50
|
+
}
|
|
51
|
+
if (this.fixed != fx) {
|
|
52
|
+
this.fixed = fx
|
|
53
|
+
this.$emit('change', this.fixed)
|
|
54
|
+
this.width = rect.width
|
|
55
|
+
this.height = rect.height
|
|
103
56
|
}
|
|
104
57
|
}
|
|
105
58
|
},
|
|
@@ -112,13 +65,8 @@ export default {
|
|
|
112
65
|
}
|
|
113
66
|
fixedStyle = {
|
|
114
67
|
width: `${this.width}px`,
|
|
115
|
-
height: `${this.height}px
|
|
116
|
-
|
|
117
|
-
if (this.offsetModeOfBottom) {
|
|
118
|
-
fixedStyle.bottom = `${this.offsetBottom}px`
|
|
119
|
-
}
|
|
120
|
-
if (this.offsetModeOfTop) {
|
|
121
|
-
fixedStyle.top = `${this.offsetTopValue}px`
|
|
68
|
+
height: `${this.height}px`,
|
|
69
|
+
top: `${this.offsetTopValue}px`
|
|
122
70
|
}
|
|
123
71
|
classes = { ['k-affix']: this.fixed }
|
|
124
72
|
}
|
|
@@ -7,25 +7,32 @@
|
|
|
7
7
|
<template>
|
|
8
8
|
<div class="demo-affix-scroll" ref="container">
|
|
9
9
|
<div class="demo-affix-inner" >
|
|
10
|
-
<
|
|
10
|
+
<div style="padding:50px 0;" />
|
|
11
|
+
<Affix :target="() => this.$refs.container" :offsetTop="50">
|
|
11
12
|
<Button type="primary" id="tesss">Affix at the top of container</Button>
|
|
12
13
|
</Affix>
|
|
14
|
+
<div style="padding:200px 0;" />
|
|
15
|
+
<Affix :target="() => this.$refs.container" :offsetBottom="50">
|
|
16
|
+
<Button type="primary" id="tesss">Affix at the bottom of container</Button>
|
|
17
|
+
</Affix>
|
|
13
18
|
</div>
|
|
14
19
|
</div>
|
|
15
20
|
</template>
|
|
16
21
|
|
|
17
22
|
<style scoped>
|
|
18
23
|
.demo-affix-scroll{
|
|
19
|
-
height:
|
|
24
|
+
height:400px;
|
|
20
25
|
overflow-y:scroll;
|
|
26
|
+
background-image: linear-gradient(-45deg, #cdcdcd 25%, transparent 0), linear-gradient(45deg, #cdcdcd 25%, transparent 0), linear-gradient(-45deg, transparent 75%, #cdcdcd 0), linear-gradient(45deg, transparent 75%, #cdcdcd 0);
|
|
27
|
+
background-size: 20px 20px;
|
|
28
|
+
background-position: 0 0, 0 -10px, -10px 10px, 10px 0;
|
|
21
29
|
}
|
|
22
30
|
.demo-affix-inner{
|
|
23
|
-
height:
|
|
31
|
+
height:800px;
|
|
24
32
|
/* background:#efefef; */
|
|
25
|
-
padding-top:30px;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
background-position: 0 0, 0 -10px, -10px 10px, 10px 0;
|
|
33
|
+
/* padding-top:30px; */
|
|
34
|
+
|
|
35
|
+
|
|
29
36
|
}
|
|
30
37
|
</style>
|
|
31
38
|
```
|