Appearance
围绕中心球体旋转动画
在一个数据大屏的项目中,有个模块有点意思就分享一下,我同事在jq22上看到一个类似的,但是项目代码非常多,乱七八糟的,虽然他弄出来了,但我觉得不好,于是在网上找了一下,找到一个差不多的,最后经过修改比我同事那个简化超级多,一眼就看懂的,简化了很多复杂的代码
效果:呈椭圆状围绕着中心的球体旋转
js
<template>
<div class="top_data">
<div class="title">未来展望</div>
<div class="err">
<div class="content">
<div class="main">
<div class="round">
<div class="title">执行总数</div>
<div class="sum">{{rslist}}</div>
</div>
<!-- <div id="lopp"></div> -->
<div :class="'ball ball'+(index+1)" v-for="(item,index) in list" :key="index">
<img src="@/assets/img/future-item.png" alt="">
<span class="text">{{item}}</span>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import {futureApi} from "../../../api/api"
export default {
name: 'Future',
data() {
return {
list:[],
rslist:{}
}
},
created() {
this.getData()
},
methods: {
async getData(){
let res = await futureApi()
this.list = res.data.legend;
this.rslist = res.data.total;
},
}
}
</script>
<style lang="less" scoped>
.top_data {
background: url('@/assets/img/d1.png') no-repeat;
background-size: 100% 100%;
width: 506px;
height: 351px;
margin-left: auto;
}
.title {
font-size: 22px;
font-weight: bold;
color: #FFFFFF;
padding: 30px 50px 10px;
font-family: SourceHanSerifCN-Regular-Bold;
}
@keyframes animX {
0% {
left: 105px;
}
100% {
left: 460px;
}
}
@keyframes animY {
0% {
top: 50px;
}
100% {
top: 110px;
}
}
@keyframes scale {
0% {
transform: scale(0.5)
}
50% {
transform: scale(1)
}
100% {
transform: scale(0.5)
}
}
.content{
width: 650px;
height: 196px;
background: url("@/assets/img/future_bg.png") no-repeat;
background-size: 100% 100%;
background-position: center center;
position: relative;
top: 50px;
left: -80px;
}
// #lopp {
// width: 342px;
// height: 54px;
// border: 2px solid #999;
// border-radius: 50%;
// position: absolute;
// left: 153px;
// top: 79px;
// // left: 50%;
// // transform: translateX(-50%);
// // bottom: 222px;
// }
.ball {
width: 90px;
position: absolute;
color: #fff;
font-size: 18px;
font-family: SourceHanSerifCN-Regular-Bold;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
img{
width: 50px;
height: 50px;
border-radius: 50%;
}
.text{
color: #fff;
font-size: 14px;
}
}
.main{
.round{
width: 80px;
height: 80px;
box-sizing: border-box;
border-radius: 50%;
background: url("@/assets/img/future_bg.png") no-repeat;
background-position: -285px -37px;
background-size: 650px 196px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: absolute;
left: 287px;
top: 36px;
z-index: 9;
.title{
font-size: 11px;
font-weight: bold;
font-family: SourceHanSerifCN-Regular-Bold;
color: #FFFFFF;
text-align: center;
padding: 0;
}
.sum{
font-size: 18px;
font-weight: bold;
font-family: SourceHanSerifCN-Regular-Bold;
color: #FFFFFF;
text-align: center;
margin-top: 7px;
}
}
}
//实际上人家是7个圆的,我的项目是8个,但我变成8个的时候旋转时有一点点抖动
//7个圆,x和y轴动画加起来是20s , 20s/7 约等于 2.857s
//每个球y轴动画延迟 从0递减2.857s,x轴与y相差动画时长的一半(10s/2)
.ball1 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate;
}
.ball2 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -7.5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -2.5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -2.5s infinite alternate;
}
.ball3 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -5s infinite alternate;
}
.ball4 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -12.5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -7.5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -7.5s infinite alternate;
}
.ball5 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -15s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate;
}
.ball6 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -17.5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -12.5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -12.5s infinite alternate;
}
.ball7 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -20s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -15s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -15s infinite alternate;
}
.ball8 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -22.5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -17.5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -17.5s infinite alternate;
}
</style>
<template>
<div class="top_data">
<div class="title">未来展望</div>
<div class="err">
<div class="content">
<div class="main">
<div class="round">
<div class="title">执行总数</div>
<div class="sum">{{rslist}}</div>
</div>
<!-- <div id="lopp"></div> -->
<div :class="'ball ball'+(index+1)" v-for="(item,index) in list" :key="index">
<img src="@/assets/img/future-item.png" alt="">
<span class="text">{{item}}</span>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import {futureApi} from "../../../api/api"
export default {
name: 'Future',
data() {
return {
list:[],
rslist:{}
}
},
created() {
this.getData()
},
methods: {
async getData(){
let res = await futureApi()
this.list = res.data.legend;
this.rslist = res.data.total;
},
}
}
</script>
<style lang="less" scoped>
.top_data {
background: url('@/assets/img/d1.png') no-repeat;
background-size: 100% 100%;
width: 506px;
height: 351px;
margin-left: auto;
}
.title {
font-size: 22px;
font-weight: bold;
color: #FFFFFF;
padding: 30px 50px 10px;
font-family: SourceHanSerifCN-Regular-Bold;
}
@keyframes animX {
0% {
left: 105px;
}
100% {
left: 460px;
}
}
@keyframes animY {
0% {
top: 50px;
}
100% {
top: 110px;
}
}
@keyframes scale {
0% {
transform: scale(0.5)
}
50% {
transform: scale(1)
}
100% {
transform: scale(0.5)
}
}
.content{
width: 650px;
height: 196px;
background: url("@/assets/img/future_bg.png") no-repeat;
background-size: 100% 100%;
background-position: center center;
position: relative;
top: 50px;
left: -80px;
}
// #lopp {
// width: 342px;
// height: 54px;
// border: 2px solid #999;
// border-radius: 50%;
// position: absolute;
// left: 153px;
// top: 79px;
// // left: 50%;
// // transform: translateX(-50%);
// // bottom: 222px;
// }
.ball {
width: 90px;
position: absolute;
color: #fff;
font-size: 18px;
font-family: SourceHanSerifCN-Regular-Bold;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
img{
width: 50px;
height: 50px;
border-radius: 50%;
}
.text{
color: #fff;
font-size: 14px;
}
}
.main{
.round{
width: 80px;
height: 80px;
box-sizing: border-box;
border-radius: 50%;
background: url("@/assets/img/future_bg.png") no-repeat;
background-position: -285px -37px;
background-size: 650px 196px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: absolute;
left: 287px;
top: 36px;
z-index: 9;
.title{
font-size: 11px;
font-weight: bold;
font-family: SourceHanSerifCN-Regular-Bold;
color: #FFFFFF;
text-align: center;
padding: 0;
}
.sum{
font-size: 18px;
font-weight: bold;
font-family: SourceHanSerifCN-Regular-Bold;
color: #FFFFFF;
text-align: center;
margin-top: 7px;
}
}
}
//实际上人家是7个圆的,我的项目是8个,但我变成8个的时候旋转时有一点点抖动
//7个圆,x和y轴动画加起来是20s , 20s/7 约等于 2.857s
//每个球y轴动画延迟 从0递减2.857s,x轴与y相差动画时长的一半(10s/2)
.ball1 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate;
}
.ball2 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -7.5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -2.5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -2.5s infinite alternate;
}
.ball3 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -5s infinite alternate;
}
.ball4 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -12.5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -7.5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -7.5s infinite alternate;
}
.ball5 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -15s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate;
}
.ball6 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -17.5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -12.5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -12.5s infinite alternate;
}
.ball7 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -20s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -15s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -15s infinite alternate;
}
.ball8 {
animation: animX 10s cubic-bezier(0.36, 0, 0.64, 1) -22.5s infinite alternate,
animY 10s cubic-bezier(0.36, 0, 0.64, 1) -17.5s infinite alternate,
scale 20s cubic-bezier(0.36, 0, 0.64, 1) -17.5s infinite alternate;
}
</style>