android仿饿了么购物车效果,仿饿了么购物车跳动

[TOC]

#### 仿饿了么购物车跳动动画

![](https://box.kancloud.cn/bf611640c99eeafe18dfd4471cf47ebe_377x450.png)

* [ ] 实现思路

1. 点击添加购物按钮,发布事件给父组件

2. 父组件监听事件,改变全局变量,延迟500ms后在还原变量

* [ ] 实现代码

1. vuex 中添加全局变量,控制动画显示 / 隐藏

~~~

export default {

state: {

showCart: false // 控制动画样式显示 || 隐藏

},

~~~

*****

2. 绑定动画样式

![](https://box.kancloud.cn/41c5eb9b260467c1d1cce30ec1eb5fee_386x65.png)

~~~

{{totalCount}}

~~~

~~~

.left-cart

flex 0 0 54px

width 54px

height 54px

margin -10px 16px 0 16px

z-index 9999

border-radius 50%

background-color: #131d26;

display flex

align-items center

justify-content center

&.animationShake

animation:bottomNav-shake .5s ease-in-out

@keyframes bottomNav-shake

0%

transform scale(1)

25%

transform scale(.8)

50%

transform scale(1.1)

75%

transform scale(0.9)

to

transform scale(1)

~~~

*****

3. 监听添加购物按钮,发布事件

![](https://box.kancloud.cn/aae67daf98a887232af51056637ee890_295x175.png)

~~~

~~~

~~~

methods: {

plus() {

if (!this.foods.count) {

this.$set(this.foods, 'count', 1)

} else {

this.foods.count++

}

this.$emit('add')

},

~~~

*****

4.父组件监听事件,执行逻辑

~~~

~~~

~~~

methods: {

onAddHandle() {

this.setShowCart(true).then(() => {

setTimeout(() => {

// 调用子组件方法,隐藏样式

this.$refs.shopCart.hide()

},500)

})

}

},

~~~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值