mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +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">
|
||||
<!----></i>
|
||||
<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 class="van-image-preview__index">1 / 0</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">
|
||||
<!----></i>
|
||||
<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 class="van-image-preview__index">1 / 0</div>
|
||||
</div>
|
||||
@ -23,7 +23,7 @@ exports[`close-icon-position prop 1`] = `
|
||||
exports[`cover slot 1`] = `
|
||||
<div class="van-image-preview" name="van-fade">
|
||||
<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 class="van-image-preview__index">1 / 0</div>
|
||||
<div class="van-image-preview__cover">Custom Cover Content</div>
|
||||
@ -33,7 +33,7 @@ exports[`cover slot 1`] = `
|
||||
exports[`index slot 1`] = `
|
||||
<div class="van-image-preview" name="van-fade">
|
||||
<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 class="van-image-preview__index">Custom Index</div>
|
||||
</div>
|
||||
@ -55,7 +55,7 @@ exports[`render image 1`] = `
|
||||
exports[`set show-index prop to false 1`] = `
|
||||
<div class="van-image-preview" name="van-fade">
|
||||
<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>
|
||||
`;
|
||||
|
@ -149,31 +149,25 @@ export default createComponent({
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.initRect();
|
||||
this.bindTouchEvent(this.$refs.track);
|
||||
},
|
||||
|
||||
methods: {
|
||||
initRect() {
|
||||
this.rect = this.$el.getBoundingClientRect();
|
||||
},
|
||||
|
||||
// initialize swipe position
|
||||
initialize(active = +this.initialSwipe) {
|
||||
if (!this.rect) {
|
||||
if (!this.$el || isHidden(this.$el)) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(this.timer);
|
||||
|
||||
if (this.$el && !isHidden(this.$el)) {
|
||||
const { rect } = this;
|
||||
this.computedWidth = Math.round(+this.width || rect.width);
|
||||
this.computedHeight = Math.round(+this.height || rect.height);
|
||||
}
|
||||
const rect = this.$el.getBoundingClientRect();
|
||||
|
||||
this.rect = rect;
|
||||
this.swiping = true;
|
||||
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.children.forEach((swipe) => {
|
||||
swipe.offset = 0;
|
||||
@ -183,7 +177,6 @@ export default createComponent({
|
||||
|
||||
// @exposed-api
|
||||
resize() {
|
||||
this.initRect();
|
||||
this.initialize(this.activeIndicator);
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user