mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
fix(Collapse): 修复没有动画效果 @rex-zsd (#1140)
This commit is contained in:
parent
6fd37fc5b9
commit
c75d37e61b
@ -27,8 +27,6 @@
|
|||||||
|
|
||||||
&__wrapper {
|
&__wrapper {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
will-change: max-height;
|
|
||||||
transition: max-height @collapse-item-transition-duration ease-in-out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__content {
|
&__content {
|
||||||
|
@ -33,6 +33,13 @@ VantComponent({
|
|||||||
expanded: false
|
expanded: false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
beforeCreate() {
|
||||||
|
this.animation = wx.createAnimation({
|
||||||
|
duration: 300,
|
||||||
|
timingFunction: 'ease-in-out'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
updateExpanded() {
|
updateExpanded() {
|
||||||
if (!this.parent) {
|
if (!this.parent) {
|
||||||
@ -56,16 +63,27 @@ VantComponent({
|
|||||||
this.set({ expanded });
|
this.set({ expanded });
|
||||||
},
|
},
|
||||||
|
|
||||||
updateStyle(expanded) {
|
updateStyle(expanded: boolean) {
|
||||||
if (expanded) {
|
this.getRect('.van-collapse-item__content').then(res => {
|
||||||
this.set({
|
const animationData = this.animation
|
||||||
contentHeight: 'auto'
|
.height(expanded ? res.height : 0)
|
||||||
});
|
.step()
|
||||||
} else {
|
.export();
|
||||||
this.set({
|
if (expanded) {
|
||||||
contentHeight: 0
|
this.set({ animationData });
|
||||||
});
|
} else {
|
||||||
}
|
this.set(
|
||||||
|
{
|
||||||
|
contentHeight: res.height + 'px'
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.set({ animationData });
|
||||||
|
}, 20);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onClick() {
|
onClick() {
|
||||||
@ -79,6 +97,14 @@ VantComponent({
|
|||||||
const currentName = name == null ? index : name;
|
const currentName = name == null ? index : name;
|
||||||
|
|
||||||
this.parent.switch(currentName, !expanded);
|
this.parent.switch(currentName, !expanded);
|
||||||
|
},
|
||||||
|
|
||||||
|
onTransitionEnd() {
|
||||||
|
if (this.data.expanded) {
|
||||||
|
this.set({
|
||||||
|
contentHeight: 'auto'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
</van-cell>
|
</van-cell>
|
||||||
<view
|
<view
|
||||||
class="van-collapse-item__wrapper"
|
class="van-collapse-item__wrapper"
|
||||||
style="max-height: {{ contentHeight }};"
|
style="height: {{ contentHeight }};"
|
||||||
|
animation="{{ animationData }}"
|
||||||
|
bind:transitionend="onTransitionEnd"
|
||||||
>
|
>
|
||||||
<view
|
<view
|
||||||
class="van-collapse-item__content content-class"
|
class="van-collapse-item__content content-class"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user