css实现上下轻微来回晃动效果

css yekong

vue项目开发中,为了让项目看起来更活泼,会给对应的组件增加一些动画,今天我们通过css实现上下轻微来回晃动效果。

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: pieMove 5s ease-in 0s infinite alternate;
    animation: pieMove 5s ease-in 0s infinite alternate;
    background: red;
  }
}

@-webkit-keyframes pieMove {
  0% {
    transform: translate(0px, 0px)
  }
  25% {
    transform: translate(5px, -4px)
  }
  50% {
    transform: translate(2px, 5px)
  }
  75% {
    transform: translate(5px, 0px)
  }
  100% {
    transform: translate(0px, 5px)
  }
}

@-moz-keyframes pieMove {
  0% {
    transform: translate(0px, 0px)
  }
  25% {
    transform: translate(5px, -4px)
  }
  50% {
    transform: translate(2px, 5px)
  }
  75% {
    transform: translate(5px, 0px)
  }
  100% {
    transform: translate(0px, 5px)
  }
}

@-ms-keyframes pieMove {
  0% {
    transform: translate(0px, 0px)
  }
  25% {
    transform: translate(5px, -4px)
  }
  50% {
    transform: translate(2px, 5px)
  }
  75% {
    transform: translate(5px, 0px)
  }
  100% {
    transform: translate(0px, 5px)
  }
}

@keyframes pieMove {
  0% {
    transform: translate(0px, 0px)
  }
  25% {
    transform: translate(5px, -4px)
  }
  50% {
    transform: translate(2px, 5px)
  }
  75% {
    transform: translate(5px, 0px)
  }
  100% {
    transform: translate(0px, 5px)
  }
}


</style>

喜欢