当前位置:   article > 正文

`CSS`----图标`3D`环绕旋转,近大远小效果_css图片旋转3d旋转

css图片旋转3d旋转

CSS----图标3D环绕旋转,近大远小效果

1、先设置图标底部圆环,图片为一张正圆图,给图片外层盒子设置 transform: scaleY(0.25);,将图片效果转为椭圆
代码如下:
  <div class="entry-box">
      <div class="entry-box-content">
        <div class="content-circle">
          <div
            class="circle"
          ></div>
        </div>
      </div>
    </div>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  .entry-box {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    &-content {
      width: 50vw;
      height: 50vw;
      position: absolute;
      top: calc(50% - 25vw);
      left: 25vw;
      z-index: 1;
         .content-circle {
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        transform: scaleY(0.25);//将背景圆设置为3D效果

        .circle {
          width: 100%;
          height: 100%;
          border-radius: 50%;
          background: url("../../assets/bgImg/circular5.png") no-repeat center center;
          background-size: 100% 100%;
        }
      }
      }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
效果图

在这里插入图片描述

2、给底部圆环添加动画
  .circle {
          width: 100%;
          height: 100%;
          border-radius: 50%;
          background: url("../../assets/bgImg/circular5.png") no-repeat center center;
          background-size: 100% 100%;
          animation: centerRotate 15s linear infinite;
        }

@keyframes centerRotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
3、引入图标,并渲染到页面
import icon1 from "@/assets/iconImg/GEO终端.png";
import icon2 from "@/assets/iconImg/MF终端.png";
import icon3 from "@/assets/iconImg/pad.png";
import icon4 from "@/assets/iconImg/手机.png";
import icon5 from "@/assets/iconImg/显示器.png";
import icon6 from "@/assets/iconImg/服务器.png";
import icon7 from "@/assets/iconImg/笔记本.png";
import icon8 from "@/assets/iconImg/视频终端.png";

const IconList = [
  { id: 1, iconImg: icon1 },
  { id: 2, iconImg: icon2 },
  { id: 3, iconImg: icon3 },
  { id: 4, iconImg: icon4 },
  { id: 5, iconImg: icon5 },
  { id: 6, iconImg: icon6 },
  { id: 7, iconImg: icon7 },
  { id: 8, iconImg: icon8 },
];

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
 <div
          :class="['icon', 'icon' + item.id]"
          v-for="item in IconList"
          :key="item.id"
         
        >
          <img :src="item.iconImg" alt="" />
        </div>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
4、设置每个图标的位置,并给每个图标添加动画
 <div
          :class="['icon', 'icon' + item.id]"
          v-for="item in IconList"
          :key="item.id"
         
        >
          <img :src="item.iconImg" alt="" />
        </div>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
   .icon {
        width: 6vw;
        height: 6vw;
        position: absolute;
        display: flex;
        justify-content: center;
        align-items: center;

        img {
          width: 120%;
        }

        img:hover {
          width: 140%;
        }
      }     
      .icon1 {
        top: 24vw;
        left: 22vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -4s infinite alternate,
                   turnY 8s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate,
                   turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate;
      }
      .icon2 {
        top: 22.25vw;
        left: 11.25vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -6s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -2s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -2s infinite alternate;
      }
      .icon3 {
        top: 19vw;
        left: 3vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -8s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -4s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -4s infinite alternate;
      }
      .icon4 {
        top: 15.25vw;
        left: 11.25vw;
        animation: turnX  8s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
                   turnY  8s cubic-bezier(0.36, 0, 0.64, 1) -6s infinite alternate,
                   turn-self 16s cubic-bezier(0.36, 0, 0.64, 1)-6s infinite alternate;
      }
      .icon5 {
        top: 14.5vw;
        left: 22vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -12s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -8s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -8s infinite alternate;
      }
      .icon6 {
        top: 15.25vw;
        right: 11.25vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -14s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate;
      }
      .icon7 {
        top: 19vw;
        left: 41vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -16s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -12s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -12s infinite alternate;
      }

      .icon8 {
        top: 22.25vw;
        right: 11.25vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -18s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -14s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -14s infinite alternate;
      }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

1、第一个icon初始值

turn-self :duration为 turnX和turnY之和

turnX:delay 为turn-self duration一半

turnY,turn-self :delay 为 0

2、每个delay 每次递减的值为 turn-self的duration/icon的数量 例子:16/8 = 2,每次递减2;

3、cubic-bezier,css3贝塞尔曲线 一条表示进度变化快慢的速度曲线

/* icon自身的大小缩放 */
@keyframes turn-self {
  0% {
    transform: scale(0.7);
  }

  50% {
    transform: scale(1);
  }

  100% {
    transform: scale(0.7);
  }
}

/* icon横向运动变化,x轴的范围 */
@keyframes turnX {
  0% {
    left: 3vw;
  }

  100% {
    left: 41vw;
  }
}

/*icon纵向运动变化,Y轴的范围 */
@keyframes turnY {
  0% {
    top: 14.5vw;
  }

  100% {
    top: 24vw;
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

效果图:

在这里插入图片描述

5、设置鼠标移入移出效果
 <div
          :class="['icon', 'icon' + item.id]"
          v-for="item in IconList"
          :key="item.id"
          :style="`animation-play-state: ${animationPlayState};`"
          @mouseover="mouseOver"
          @mouseleave="mouseleave"
        >
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
let animationPlayState = ref<string>("");

function mouseOver() {
  animationPlayState.value = "paused";
}
function mouseleave() {
  animationPlayState.value = "running";
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
6、完整代码
<template>
  <div class="entry">
    <div class="entry-box">
      <div class="entry-box-content">
        <div class="content-circle">
          <div
            class="circle"
            :style="`animation-play-state: ${animationPlayState};`"
          ></div>
        </div>
        <div
          :class="['icon', 'icon' + item.id]"
          v-for="item in IconList"
          :key="item.id"
          :style="`animation-play-state: ${animationPlayState}; --item:${-(
            item.id + 1
          )}; --icon:${-(item.id - 1)}`"
          @mouseover="mouseOver"
          @mouseleave="mouseleave"
        >
          <img :src="item.iconImg" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
<script lang="ts" setup>
import icon1 from "@/assets/iconImg/GEO终端.png";
import icon2 from "@/assets/iconImg/MF终端.png";
import icon3 from "@/assets/iconImg/pad.png";
import icon4 from "@/assets/iconImg/手机.png";
import icon5 from "@/assets/iconImg/显示器.png";
import icon6 from "@/assets/iconImg/服务器.png";
import icon7 from "@/assets/iconImg/笔记本.png";
import icon8 from "@/assets/iconImg/视频终端.png";

const IconList = [
  { id: 1, iconImg: icon1 },
  { id: 2, iconImg: icon2 },
  { id: 3, iconImg: icon3 },
  { id: 4, iconImg: icon4 },
  { id: 5, iconImg: icon5 },
  { id: 6, iconImg: icon6 },
  { id: 7, iconImg: icon7 },
  { id: 8, iconImg: icon8 },
];

let animationPlayState = ref<string>("");

function mouseOver() {
  animationPlayState.value = "paused";
}
function mouseleave() {
  animationPlayState.value = "running";
}
</script>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
<style lang="scss" scoped>
.entry {
  width: 100%;
  height: 100%;
  display: flex;
  position: relative;

  .entry-box {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    &-content {
      width: 50vw;
      height: 50vw;
      position: absolute;
      top: calc(50% - 25vw);
      left:25vw;
      z-index: 1;
      .content-circle {
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        transform: scaleY(0.25);

        .circle {
          width: 100%;
          height: 100%;
          border-radius: 50%;
          background: url("../../assets/bgImg/circular5.png") no-repeat center center;
          background-size: 100% 100%;
          animation: centerRotate 15s linear infinite;
        }
      }
      .icon {
        width: 6vw;
        height: 6vw;
        position: absolute;
        display: flex;
        justify-content: center;
        align-items: center;

        img {
          width: 120%;
        }

        img:hover {
          width: 140%;
        }
      }
      .icon1 {
        top: 24vw;
        left: 22vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -4s infinite alternate,
                   turnY 8s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate,
                   turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate;
      }
      .icon2 {
        top: 22.25vw;
        left: 11.25vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -6s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -2s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -2s infinite alternate;
      }
      .icon3 {
        top: 19vw;
        left: 3vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -8s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -4s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -4s infinite alternate;
      }
      .icon4 {
        top: 15.25vw;
        left: 11.25vw;
        animation: turnX  8s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
                   turnY  8s cubic-bezier(0.36, 0, 0.64, 1) -6s infinite alternate,
                   turn-self 16s cubic-bezier(0.36, 0, 0.64, 1)-6s infinite alternate;
      }
      .icon5 {
        top: 14.5vw;
        left: 22vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -12s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -8s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -8s infinite alternate;
      }
      .icon6 {
        top: 15.25vw;
        right: 11.25vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -14s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate;
      }
      .icon7 {
        top: 19vw;
        left: 41vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -16s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -12s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -12s infinite alternate;
      }

      .icon8 {
        top: 22.25vw;
        right: 11.25vw;
        animation: turnX 8s cubic-bezier(0.36, 0, 0.64, 1) -18s infinite alternate,
          turnY 8s cubic-bezier(0.36, 0, 0.64, 1) -14s infinite alternate,
          turn-self 16s cubic-bezier(0.36, 0, 0.64, 1) -14s infinite alternate;
      }
    }
  }
}

@keyframes centerRotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* icon自身的大小缩放 */
@keyframes turn-self {
  0% {
    transform: scale(0.7);
  }

  50% {
    transform: scale(1);
  }

  100% {
    transform: scale(0.7);
  }
}

/* icon横向运动变化,x轴的范围 */
@keyframes turnX {
  0% {
    left: 3vw;
  }

  100% {
    left: 41vw;
  }
}

/*icon纵向运动变化,Y轴的范围 */
@keyframes turnY {
  0% {
    top: 14.5vw;
  }

  100% {
    top: 24vw;
  }
}
</style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/134895
推荐阅读
相关标签
  

闽ICP备14008679号