vue在做大屏项目开发时,需要添加一些动画元素,于是就研究如何做才能让页面的细节动画更生动。旋转动画是其中的一个小思路。
使用代码
<rotate>
<img class="yali" src="../assets/page/icon_yali.png" alt="">
</rotate>
组件代码
/**
* @Author: 858834013@qq.com
* @Name: rotating
* @Date: 2022-07-25
* @Desc: 旋转背景动画
*/
<template>
<div class="rotating">
<div class="rotatingInner rotatingBody">
</div>
<div class="slot">
<slot></slot>
</div>
</div>
</template>
<script>
export default {
name: "xuanzhuan",
components: {},
props: {
id: {
type: String,
default() {
return '';
}
}
},
data() {
return {
status: ''
}
},
watch: {},
mounted() {
},
methods: {}
}
</script>
<style lang="scss" scoped>
.rotating {
width: 72px;
height: 72px;
position: relative;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
}
.slot {
width: 72px;
height: 72px;
position: absolute;
top: 0;
left: 0;
display: flex;
z-index: 10;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
}
.rotatingBody {
animation: rotate 6s linear infinite;
}
.rotatingInner {
background: url("../assets/page/yuanquan.png") center center no-repeat;
width: 72px;
height: 72px;
background-size: 100% 100%;
position: absolute;
top: 0;
left: 0;
}
@keyframes rotate {
0% {
transform: rotateZ(0deg); /*从0度开始*/
}
100% {
transform: rotateZ(360deg); /*360度结束*/
}
}
</style>