带有flex / grid包装器的vue过渡组项目移至左上角

问题描述 投票:0回答:1

我有这个:

<transition-group
    name="product-list"
    tag="section"
    class="product-list"
    @before-leave="beforeLeave"
>
    <product
        v-for="watch in watches"
        :key="watch.id"
        :item="watch"
    >
    </product>
</transition-group>

并且如文档中所述:

.product-list-enter-active,
.product-list-leave-active {
    transition: all 0.3s;
}
.product-list-enter,
.product-list-leave-to {
    opacity: 0;
    transform: scale(0.5);
}
.product-list-leave-active {
    position: absolute;
}

Issue:当任何元素离开(从列表中删除)它从左上角移到顶部时,由于位置绝对...这有点破坏了它的美观性]

我有这个:]

vuejs2 flexbox transition css-grid
1个回答
0
投票

找到此解决方案:

<transition-group
    @before-leave="beforeLeave">
    ...
</transition>
methods: {
    beforeLeave(el) {
        const {marginLeft, marginTop, width, height} = window.getComputedStyle(el)

        el.style.left = `${el.offsetLeft - parseFloat(marginLeft, 10)}px`
        el.style.top = `${el.offsetTop - parseFloat(marginTop, 10)}px`
        el.style.width = width
        el.style.height = height
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.