mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Picker): incorrect position when pause momentum (#4277)
This commit is contained in:
parent
6ae352882c
commit
93ef02c409
@ -76,6 +76,10 @@ export default createComponent({
|
|||||||
computed: {
|
computed: {
|
||||||
count() {
|
count() {
|
||||||
return this.options.length;
|
return this.options.length;
|
||||||
|
},
|
||||||
|
|
||||||
|
baseOffset() {
|
||||||
|
return (this.itemHeight * (this.visibleItemCount - 1)) / 2;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -85,13 +89,13 @@ export default createComponent({
|
|||||||
|
|
||||||
if (this.moving) {
|
if (this.moving) {
|
||||||
const translateY = getElementTranslateY(this.$refs.wrapper);
|
const translateY = getElementTranslateY(this.$refs.wrapper);
|
||||||
this.startOffset = Math.min(0, translateY);
|
this.offset = Math.min(0, translateY - this.baseOffset);
|
||||||
|
this.startOffset = this.offset;
|
||||||
} else {
|
} else {
|
||||||
this.startOffset = this.offset;
|
this.startOffset = this.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.duration = 0;
|
this.duration = 0;
|
||||||
this.moving = false;
|
|
||||||
this.transitionEndTrigger = null;
|
this.transitionEndTrigger = null;
|
||||||
this.touchStartTime = Date.now();
|
this.touchStartTime = Date.now();
|
||||||
this.momentumOffset = this.startOffset;
|
this.momentumOffset = this.startOffset;
|
||||||
@ -129,11 +133,9 @@ export default createComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.offset !== this.startOffset) {
|
|
||||||
this.duration = DEFAULT_DURATION;
|
|
||||||
const index = this.getIndexByOffset(this.offset);
|
const index = this.getIndexByOffset(this.offset);
|
||||||
|
this.duration = DEFAULT_DURATION;
|
||||||
this.setIndex(index, true);
|
this.setIndex(index, true);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onTransitionEnd() {
|
onTransitionEnd() {
|
||||||
@ -228,12 +230,9 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { itemHeight, visibleItemCount } = this;
|
const { itemHeight } = this;
|
||||||
|
|
||||||
const baseOffset = (itemHeight * (visibleItemCount - 1)) / 2;
|
|
||||||
|
|
||||||
const wrapperStyle = {
|
const wrapperStyle = {
|
||||||
transform: `translate3d(0, ${this.offset + baseOffset}px, 0)`,
|
transform: `translate3d(0, ${this.offset + this.baseOffset}px, 0)`,
|
||||||
transitionDuration: `${this.duration}ms`,
|
transitionDuration: `${this.duration}ms`,
|
||||||
transitionProperty: this.duration ? 'all' : 'none',
|
transitionProperty: this.duration ? 'all' : 'none',
|
||||||
lineHeight: `${itemHeight}px`
|
lineHeight: `${itemHeight}px`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user