vue3 动画实例实现鼠标移入放大移出缩小效果

一、推荐一个不错的开源动画插件:Animate.css

1、动画官网 Animate.css | A cross-browser library of CSS animations.

2、浏览器打开cdn地址可查看全部源码 ctrl+f 搜索自己想要的动画名称即可查看对应源码cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.css

3、封装示例——动画组件源码

<template>
  <div
    :class="[
      enterShow ? 'animate__pulse__diy' : '',
      leaveShow ? 'animate__subse__diy' : '',
      'boxplus'
    ]"
    @mouseenter="onMouseenter"
    @mouseleave="onMouseleave"
  >
    <slot></slot>
  </div>
</template>
<script>
import { ref } from 'vue'
export default {
  setup() {
    const enterShow = ref(false)
    const leaveShow = ref(false)
    const onMouseenter = () => {
      enterShow.value = true
      leaveShow.value = false
    }
    const onMouseleave = () => {
      enterShow.value = false
      leaveShow.value = true
    }
    return {
      enterShow,
      leaveShow,
      onMouseenter,
      onMouseleave
    }
  }
}
</script>
<style lang="scss" scoped>
@-webkit-keyframes pulses {
  from {
    -webkit-transform: scale3d(1, 1, 1);
    transform: scale3d(1, 1, 1);
  }
  to {
    -webkit-transform: scale3d(1.05, 1.05, 1.05);
    transform: scale3d(1.05, 1.05, 1.05);
  }
}
@keyframes pulses {
  from {
    -webkit-transform: scale3d(1, 1, 1);
    transform: scale3d(1, 1, 1);
  }
  to {
    -webkit-transform: scale3d(1.05, 1.05, 1.05);
    transform: scale3d(1.05, 1.05, 1.05);
  }
}
@-webkit-keyframes subses {
  from {
    -webkit-transform: scale3d(105%, 105%, 105%);
    transform: scale3d(105%, 105%, 105%);
  }
  to {
    -webkit-transform: scale3d(1, 1, 1);
    transform: scale3d(1, 1, 1);
  }
}
@keyframes subses {
  from {
    -webkit-transform: scale3d(105%, 105%, 105%);
    transform: scale3d(105%, 105%, 105%);
  }
  to {
    -webkit-transform: scale3d(1, 1, 1);
    transform: scale3d(1, 1, 1);
  }
}
.animate__pulse__diy {
  -webkit-animation-name: pulses;
  animation-name: pulses;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
  animation: pulses 1s;
  animation-fill-mode: both;
}
.animate__subse__diy {
  -webkit-animation-name: subses;
  animation-name: subses;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
  animation: subses 0.4s;
  animation-fill-mode: both;
}
.boxplus {
  cursor: pointer;
}
</style>

动画组件引入与使用

// html
<div class="case-img-box">
  <MyPulse>
     <img :src="item.url" alt="" />
  </MyPulse>
</div>

// ts
import MyPulse from '@/yourpath'

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值