vue 实现购物车小球动画效果

html代码
<template>
  <div class="card-body">

    <!-- 商品卡片 -->
    <div class="goods-card">
      <div class="goods-img">
        <img :src="imgurl">
      </div>
      <div class="goods-title">{
  {title}}</div>
      <div class="goods-price">¥{
  {price}} </div>
      <!-- 加减商品span中的class使用的是iconfont -->
      <span v-show="show" class="iconfont icon-jian" :style="subStyle" @click="goodsSub"></span>
      <span class="goods-num" v-show="show">{
  {goodsNum}}</span>
      <span class="iconfont icon-tianjia1 add" @click="addGoods"></span>
    </div>


    <!-- 抛物线小球 -->
    <div class="cart">
      <div class="ball-wrapper" v-for="(ball, index) of balls" :key="index">
        <transition
          name="drop"
          @before-enter="beforeEnter"
          @enter="enter"
          @after-enter="afterEnter"
        >
          <div class="ball" v-show="ball.show">
            <!--这里为了做两个维度的动画,因此需要多包一层,外层做Y轴,内层做X轴动画-->
            <div class="inner inner-hook" :style="[{'background':bgcolor}]"></div>
          </div>
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue实现字母笔顺动画效果可以通过以下步骤: 1. 创建一个Vue组件,并在模板中添加一个画布元素。例如: ```html <template> <div> <canvas ref="canvas" width="300" height="300"></canvas> </div> </template> ``` 2. 在组件的mounted钩子函数中获取画布的上下文,并设置画笔的属性。例如: ```javascript mounted() { this.ctx = this.$refs.canvas.getContext('2d'); this.ctx.lineWidth = 4; this.ctx.strokeStyle = 'black'; } ``` 3. 创建一个数组,用于存储每个字母的笔画信息。例如: ```javascript data() { return { strokes: [ [[50, 50], [100, 100], [150, 50]], [[50, 150], [150, 150]], [[50, 250], [150, 250], [150, 200], [50, 200]] ] } } ``` 4. 在模板中添加一个按钮元素,并绑定一个事件处理函数,用于触发动画效果。例如: ```html <template> <div> <canvas ref="canvas" width="300" height="300"></canvas> <button @click="startAnimation">开始动画</button> </div> </template> ``` 5. 在事件处理函数中使用requestAnimationFrame函数来实现动画效果。例如: ```javascript methods: { startAnimation() { let index = 0; const animate = () => { const stroke = this.strokes[index]; this.drawStroke(stroke); index++; if (index < this.strokes.length) { requestAnimationFrame(animate); } } animate(); }, drawStroke(stroke) { this.ctx.beginPath(); this.ctx.moveTo(stroke[0][0], stroke[0][1]); for (let i = 1; i < stroke.length; i++) { this.ctx.lineTo(stroke[i][0], stroke[i][1]); } this.ctx.stroke(); } } ``` 6. 最后,可以添加一些样式来美化组件。例如: ```html <style scoped> canvas { border: 1px solid black; } button { margin-top: 10px; padding: 5px 10px; background-color: #4CAF50; border: none; color: white; font-size: 16px; cursor: pointer; } </style> ``` 这样就可以实现一个简单的字母笔顺动画效果Vue组件了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值