[new feature] IndexBar: add sticky prop (#3402)

This commit is contained in:
neverland
2019-05-30 11:50:09 +08:00
committed by GitHub
parent 74124246f6
commit 82134fe402
14 changed files with 263 additions and 60 deletions
+35 -2
View File
@@ -10,6 +10,32 @@ export default sfc({
index: [String, Number]
},
data() {
return {
top: 0,
active: false
};
},
computed: {
sticky() {
return this.active && this.parent.sticky;
},
anchorStyle() {
if (this.sticky) {
return {
top: `${this.top}px`,
zIndex: `${this.parent.zIndex}`
};
}
}
},
mounted() {
this.height = this.$el.offsetHeight;
},
methods: {
scrollIntoView() {
this.$el.scrollIntoView();
@@ -17,9 +43,16 @@ export default sfc({
},
render(h) {
const { sticky } = this;
return (
<div class={bem()}>
{this.slots('default') ? this.slots('default') : this.index}
<div style={{ height: sticky ? `${this.height}px` : null }}>
<div
style={this.anchorStyle}
class={[bem({ sticky }), { 'van-hairline--bottom': sticky }]}
>
{this.slots('default') || this.index}
</div>
</div>
);
}
+11
View File
@@ -5,4 +5,15 @@
font-weight: @index-anchor-font-weight;
font-size: @index-anchor-font-size;
line-height: @index-anchor-line-height;
background-color: transparent;
transition: background-color .2s;
&--sticky {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: 1;
background-color: #fff;
}
}