小程序购物车抛物线动画的实现,要如何开发,下面为大家介绍这篇文章。

要实现抛物线动画,我当时想到的是用插件的方式,网上有很多,但是要兼容小程序还是有点困难,况且小程序的主包有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;
}
KESION 科汛软件
KESION 科汛软件是国内领先的在线教育软件及私域社交电商软件服务提供商,长期专注于为企业提供在线教育软件及社交电商SaaS平台解决方案。
公司核心产品云开店SaaS社交电商服务平台、在线教育SaaS服务平台、教育企业数字化SaaS云平台、企微营销助手、私有化独立部署品牌网校和在线教育咨询等。KESION 不断通过技术创新,提供产品和服务,助力企业向数字化转型,通过科技驱动商业革新,让商业变得更智慧!
微信 小程序 api拦截器 完美兼容原生小程序项目 完美兼用小程序api的原本调用方式,无痛迁移 小程序api全Promise化 和axios一样的请求方式 小程序api自定义拦截调用参数和返回结果
小程序给每个行业带来很多盈利,使线下与线上人群加以联结,并带来精准的流量人群,提高了线上流量转化率,那么对于教育培训行业来说要如何去开发小程序呢。...