vue项目开发中,为了让项目看起来更活泼,会给对应的组件增加一些动画,今天我们通过css实现左下角右上角来回晃动效果。
效果
代码
<template>
<div class="cardBody" ref="body">
<div class="block">
</div>
</div>
</template>
<script>
export default {
name: "title",
data() {
return {}
},
components: {},
watch: {},
mounted() {
},
}
</script>
<style lang="scss" scoped>
.cardBody {
position: relative;
width: 100%;
overflow: hidden;
margin: 0 auto;
height: calc(100% - 10px);
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
.block {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
width: 100px;
height: 100px;
-webkit-animation: partMove 4.2s ease-in-out 0s infinite alternate;
animation: partMove 4.2s ease-in-out 0s infinite alternate;
background: red;
}
}
@-webkit-keyframes partMove {
0% {
transform: translate(0px, 0px)
}
25% {
transform: translate(10px, -10px)
}
50% {
transform: translate(2px, 10px)
}
75% {
transform: translate(8px, 0px)
}
100% {
transform: translate(0px, 10px)
}
}
@-moz-keyframes partMove {
0% {
transform: translate(0px, 0px)
}
25% {
transform: translate(10px, -10px)
}
50% {
transform: translate(2px, 10px)
}
75% {
transform: translate(8px, 0px)
}
100% {
transform: translate(0px, 10px)
}
}
@-ms-keyframes partMove {
0% {
transform: translate(0px, 0px)
}
25% {
transform: translate(10px, -10px)
}
50% {
transform: translate(2px, 10px)
}
75% {
transform: translate(8px, 0px)
}
100% {
transform: translate(0px, 10px)
}
}
@keyframes partMove {
0% {
transform: translate(0px, 0px)
}
25% {
transform: translate(10px, -10px)
}
50% {
transform: translate(2px, 10px)
}
75% {
transform: translate(8px, 0px)
}
100% {
transform: translate(0px, 10px)
}
}
</style>