【发布时间】:2019-02-21 17:07:20
【问题描述】:
我正在尝试创建一个带有 2 个按钮(向上和向下箭头)的滑块,当用户单击向上箭头时,滑块中的当前元素(居中)向上滑动并淡入淡出(即隐藏或不透明度变为 0),下一个元素从屏幕底部向上滑动,直到 opacity 变为 1。
但我似乎无法仅使用 CSS 使其工作。我设法使用 javascript (Vuejs) 复制它,但效率非常低。
<template>
<transition appear>
<div v-if="condition" class="trans-container">
<slot></slot>
</div>
</transition>
</template>
<script>
import velocity from 'velocity-animate'
export default {
name: "Slide",
props: {
condition: {
default: true,
type: Boolean
},
direction: {
type: String
}
},
methods: {
// --------
// ENTERING
// --------
beforeEnter: function (el) {
// el.style.opacity = 0
Velocity(el, {
translateY: this.direction === 'up' ? '100%' : '-100%',
opacity: 0
}, {
duration: 300
});
},
// the done callback is optional when
// used in combination with CSS
enter: function (el, done) {
Velocity(el, {
translateY: '0%',
opacity: 1
}, {
duration: 300
});
// ...
// done()
},
afterEnter: function (el) {
},
enterCancelled: function (el) {
// ...
},
// --------
// LEAVING
// --------
beforeLeave: function (el) {
Velocity(el, {
translateY: this.direction === 'down' ? '100%' : '-100%',
opacity: 0
}, {
duration: 300
});
// ...
},
// the done callback is optional when
// used in combination with CSS
leave: function (el, done) {
Velocity(el, {
translateY: this.direction === 'down' ? '100%' : '-100%',
opacity: 0
}, {
duration: 300
});
// ...
// done()
},
afterLeave: function (el) {
// ...
},
// leaveCancelled only available with v-show
leaveCancelled: function (el) {
// ...
}
}
}
</script>
<style scoped>
.trans-container {
width: 100%;
display: flex;
justify-content: space-between;
position: absolute;
align-items: center;
}
</style>
我只是无法使用 css 来做到这一点。有可能吗?
【问题讨论】:
标签: javascript html css vue.js css-transitions