直接上代码vue2代码
<template>
<div class="">
<div class="box">
<div class="left" :class="tag ? 'animationIn' : 'animationOut'">
11
</div>
<div class="right">
<div class="btn" @click="tag = !tag">
<button >点击</button>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: '',
components: {},
data() {
// 这里存放数据
return {
tag: true
}
}
}
</script>
<style lang="scss" scoped>
.btn {
/* 子元素设置绝对定位 */
position: absolute;
top: 50%;
left: -3%;
}
.box {
display: flex;
width: 600px;
height: 500px;
.animationIn {
animation: myAnimationIn 1s;
}
.animationOut {
animation: myAnimationOut 1s forwards;
}
.left {
width: 100px;
background: rgba(255, 123, 0, 0.358);
overflow: hidden;
margin-right: 10px;
}
.right {
flex: 1;
background: rgba(255, 255, 0, 0.646);
/* 父元素设置相对定位 */
position: relative;
}
@keyframes myAnimationIn {
0% {
width: 0;
}
100% {
width: 100px;
}
}
@keyframes myAnimationOut {
0% {
width: 100px;
}
100% {
width: 0;
}
}
}
</style>
效果:
收缩与展开
如果您感觉有用,请 点赞 + 收藏 + 评论 就是对我最大的支持哟 !!!