mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 09:52:57 +08:00
fix(Swipe): incorrect width after resize if hidden (#6084)
This commit is contained in:
parent
859df7bde7
commit
32b0b16cb8
@ -4,7 +4,7 @@ exports[`close-icon prop 1`] = `
|
|||||||
<div class="van-image-preview" name="van-fade"><i role="button" class="van-icon van-icon-close van-image-preview__close-icon van-image-preview__close-icon--top-right">
|
<div class="van-image-preview" name="van-fade"><i role="button" class="van-icon van-icon-close van-image-preview__close-icon van-image-preview__close-icon--top-right">
|
||||||
<!----></i>
|
<!----></i>
|
||||||
<div class="van-swipe van-image-preview__swipe">
|
<div class="van-swipe van-image-preview__swipe">
|
||||||
<div class="van-swipe__track" style="width: 0px; transition-duration: 500ms; transform: translateX(0px);"></div>
|
<div class="van-swipe__track" style="width: 0px; transition-duration: 0ms; transform: translateX(0px);"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-image-preview__index">1 / 0</div>
|
<div class="van-image-preview__index">1 / 0</div>
|
||||||
</div>
|
</div>
|
||||||
@ -14,7 +14,7 @@ exports[`close-icon-position prop 1`] = `
|
|||||||
<div class="van-image-preview" name="van-fade"><i role="button" class="van-icon van-icon-close van-image-preview__close-icon van-image-preview__close-icon--top-left">
|
<div class="van-image-preview" name="van-fade"><i role="button" class="van-icon van-icon-close van-image-preview__close-icon van-image-preview__close-icon--top-left">
|
||||||
<!----></i>
|
<!----></i>
|
||||||
<div class="van-swipe van-image-preview__swipe">
|
<div class="van-swipe van-image-preview__swipe">
|
||||||
<div class="van-swipe__track" style="width: 0px; transition-duration: 500ms; transform: translateX(0px);"></div>
|
<div class="van-swipe__track" style="width: 0px; transition-duration: 0ms; transform: translateX(0px);"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-image-preview__index">1 / 0</div>
|
<div class="van-image-preview__index">1 / 0</div>
|
||||||
</div>
|
</div>
|
||||||
@ -23,7 +23,7 @@ exports[`close-icon-position prop 1`] = `
|
|||||||
exports[`cover slot 1`] = `
|
exports[`cover slot 1`] = `
|
||||||
<div class="van-image-preview" name="van-fade">
|
<div class="van-image-preview" name="van-fade">
|
||||||
<div class="van-swipe van-image-preview__swipe">
|
<div class="van-swipe van-image-preview__swipe">
|
||||||
<div class="van-swipe__track" style="width: 0px; transition-duration: 500ms; transform: translateX(0px);"></div>
|
<div class="van-swipe__track" style="width: 0px; transition-duration: 0ms; transform: translateX(0px);"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-image-preview__index">1 / 0</div>
|
<div class="van-image-preview__index">1 / 0</div>
|
||||||
<div class="van-image-preview__cover">Custom Cover Content</div>
|
<div class="van-image-preview__cover">Custom Cover Content</div>
|
||||||
@ -33,7 +33,7 @@ exports[`cover slot 1`] = `
|
|||||||
exports[`index slot 1`] = `
|
exports[`index slot 1`] = `
|
||||||
<div class="van-image-preview" name="van-fade">
|
<div class="van-image-preview" name="van-fade">
|
||||||
<div class="van-swipe van-image-preview__swipe">
|
<div class="van-swipe van-image-preview__swipe">
|
||||||
<div class="van-swipe__track" style="width: 0px; transition-duration: 500ms; transform: translateX(0px);"></div>
|
<div class="van-swipe__track" style="width: 0px; transition-duration: 0ms; transform: translateX(0px);"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-image-preview__index">Custom Index</div>
|
<div class="van-image-preview__index">Custom Index</div>
|
||||||
</div>
|
</div>
|
||||||
@ -55,7 +55,7 @@ exports[`render image 1`] = `
|
|||||||
exports[`set show-index prop to false 1`] = `
|
exports[`set show-index prop to false 1`] = `
|
||||||
<div class="van-image-preview" name="van-fade">
|
<div class="van-image-preview" name="van-fade">
|
||||||
<div class="van-swipe van-image-preview__swipe">
|
<div class="van-swipe van-image-preview__swipe">
|
||||||
<div class="van-swipe__track" style="width: 0px; transition-duration: 500ms; transform: translateX(0px);"></div>
|
<div class="van-swipe__track" style="width: 0px; transition-duration: 0ms; transform: translateX(0px);"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -149,31 +149,25 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initRect();
|
|
||||||
this.bindTouchEvent(this.$refs.track);
|
this.bindTouchEvent(this.$refs.track);
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
initRect() {
|
|
||||||
this.rect = this.$el.getBoundingClientRect();
|
|
||||||
},
|
|
||||||
|
|
||||||
// initialize swipe position
|
// initialize swipe position
|
||||||
initialize(active = +this.initialSwipe) {
|
initialize(active = +this.initialSwipe) {
|
||||||
if (!this.rect) {
|
if (!this.$el || isHidden(this.$el)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
|
|
||||||
if (this.$el && !isHidden(this.$el)) {
|
const rect = this.$el.getBoundingClientRect();
|
||||||
const { rect } = this;
|
|
||||||
this.computedWidth = Math.round(+this.width || rect.width);
|
|
||||||
this.computedHeight = Math.round(+this.height || rect.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
this.rect = rect;
|
||||||
this.swiping = true;
|
this.swiping = true;
|
||||||
this.active = active;
|
this.active = active;
|
||||||
|
this.computedWidth = Math.round(+this.width || rect.width);
|
||||||
|
this.computedHeight = Math.round(+this.height || rect.height);
|
||||||
this.offset = this.getTargetOffset(active);
|
this.offset = this.getTargetOffset(active);
|
||||||
this.children.forEach((swipe) => {
|
this.children.forEach((swipe) => {
|
||||||
swipe.offset = 0;
|
swipe.offset = 0;
|
||||||
@ -183,7 +177,6 @@ export default createComponent({
|
|||||||
|
|
||||||
// @exposed-api
|
// @exposed-api
|
||||||
resize() {
|
resize() {
|
||||||
this.initRect();
|
|
||||||
this.initialize(this.activeIndicator);
|
this.initialize(this.activeIndicator);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user