专注连锁门店会员营销管理系统
线上+线下+进销存+收银+会员2020-09-27 作者:秩名
小程序购物车抛物线动画的实现,要如何开发,下面为大家介绍这篇文章。
要实现抛物线动画,我当时想到的是用插件的方式,网上有很多,但是要兼容小程序还是有点困难,况且小程序的主包有2M限制;
那么如何在小程序中实现这种效果呢?
wx.createAnimation css3 transition
实现方式有了,我们再来看一下什么是抛物线,数学上定义抛物线的种类有很多,但就上图的效果而言,需要 水平方向匀速运动 & 垂直方向加速运动 ; wx.createAnimation 提供 timingFunction , 即水平方向 linear , 垂直方向 ease-in
本次实现基于 wepy框架 (非小程序原生),所以 $apply ---> setData 就好了~
html
<view class="box"> <view> <button bindtap="handleClick">点击</button> </view> <view animation="{{animationY}}" style="position:fixed;top:{{ballY}}px;" hidden="{{!showBall}}"> <view class="ball" animation="{{animationX}}" style="position:fixed;left:{{ballX}}px;"></view> </view> </view>
JS
// 设置延迟时间 methods = { handleClick: (e) => { // x, y表示手指点击横纵坐标, 即小球的起始坐标 let ballX = e.detail.x, ballY = e.detail.y; this.isLoading = true; this.$apply(); this.createAnimation(ballX, ballY); } } setDelayTime(sec) { return new Promise((resolve, reject) => { setTimeout(() => {resolve()}, sec) }); } // 创建动画 createAnimation(ballX, ballY) { let that = this, bottomX = that.$parent.globalData.windowWidth, bottomY = that.$parent.globalData.windowHeight-50, animationX = that.flyX(bottomX, ballX), // 创建小球水平动画 animationY = that.flyY(bottomY, ballY); // 创建小球垂直动画 that.ballX = ballX; that.ballY = ballY; that.showBall = true; that.$apply(); that.setDelayTime(100).then(() => { // 100ms延时, 确保小球已经显示 that.animationX = animationX.export(); that.animationY = animationY.export(); that.$apply(); // 400ms延时, 即小球的抛物线时长 return that.setDelayTime(400); }).then(() => { that.animationX = this.flyX(0, 0, 0).export(); that.animationY = this.flyY(0, 0, 0).export(); that.showBall = false; that.isLoading = false; that.$apply(); }) } // 水平动画 flyX(bottomX, ballX, duration) { let animation = wx.createAnimation({ duration: duration || 400, timingFunction: 'linear', }) animation.translateX(bottomX-ballX).step(); return animation; } // 垂直动画 flyY(bottomY, ballY, duration) { let animation = wx.createAnimation({ duration: duration || 400, timingFunction: 'ease-in', }) animation.translateY(bottomY-ballY).step(); return animation; }
线上+线下+进销存+收银+会员门店零售管理好帮手
门店能实现快速收银,提升门店经营效率。
系统自带进销存管理,更好管理库存销售。
配备收银硬件一站式整体服务。
收 银 会员管理 库存管理 商品管理 交接班 数据报表 营销促单 售后处理 多种收款
获取报价推荐文章
最新消息总结,开发一个小程序我们可以选择的第三方框架有5种,大家比较熟悉的有美团小程序框架mpvue,还有组件化框架等...
最近在调研小程序的分享能力,本篇文档主要是调研小程序关于分享方面的玩法,目的是学习小程序在项目应用以及玩法链上...
许多人在使用小程序,会有一个很麻烦的事情,就是使用过小程序之后,会不断的发送自己的定位消息,那么这个小程序的...
一款小程序,很多时候需要调用内置的照相机,实现拍照并图片上传,那么要如何实现呢?...
长沙小程序制作公司选择指南 在数字化浪潮中,小程序已成为企业拓展业务、提升用户体验的重要工具。对于长沙的企业和...
长沙小程序价格百科 在长沙,小程序开发价格因多种因素而有所不同。接下来,我们将从功能需求、开发模式、设计要求这...
长沙小程序开发制作公司全知道 在数字化浪潮中,小程序已成为企业拓展业务、提升用户体验的关键工具。长沙作为互联网...
1. 长沙小程序制作公司哪家好价格便宜 在长沙,想找价格便宜且靠谱的小程序制作公司,需先了解小程序开发模式。模板类...
长沙小程序制作开发百科 在数字化浪潮中,长沙的企业与商家纷纷将目光投向小程序制作开发,期望借此拓展业务、提升用...
长沙微信小程序定制制作公司相关介绍 在数字化浪潮中,微信小程序已成为企业拓展业务、提升用户体验的重要工具。长沙...