首页 技术 正文
技术 2022年11月16日
0 收藏 627 点赞 4,731 浏览 1524 个字

对于网上商城,加入购物车是一个必备功能了。俺今天就来说下在微信小程序里如何造一个购物车弹层。

先上图:

微信小程序——加入购物车弹层

主要用到的微信API:wx.createAnimation(OBJECT)

说下思路:

1.wxml文件里将页面布局好,我的布局如下图:

微信小程序——加入购物车弹层

大概的框架代码如下:

<view class='mask-layer' wx:if="{{showPop}}" bindtap='hideModal'></view>
<view class='pop-add-cart pop-common' wx:if="{{showPop}}" animation='{{animationData}}'>
<view class='header row'>
头部区域
</view>
<scroll-view class='body' scroll-y='true'>
中间区域
</scroll-view>
<view class='footer toolbar'>
底部区域
</view>
</view>

2.wxss里面写样式,主要的样式代码如下:

.mask-layer {
width: 100%;
height: 100%;
position: fixed;
top:;
left:;
background: #000;
opacity: 0.2;
overflow: hidden;
z-index:;
color: #fff;
}
.pop-common {
width: 100%;
overflow: hidden;
position: fixed;
bottom:;
left:;
z-index:;
background: #fff;
}

3.写动画所需的js:

//获取应用实例
var app = getApp();Page({ /**
* 页面的初始数据
*/
data: {
showPop: false,
animationData: {},
}, // 显示底部弹层
showModal: function() {
var _this = this;
var animation = wx.createAnimation({
duration: 500,
timingFunction: 'ease',
delay: 0
})
_this.animation = animation
animation.translateY(300).step()
_this.setData({
animationData: animation.export(),
showPop: true
})
setTimeout(function() {
animation.translateY(0).step()
_this.setData({
animationData: animation.export()
})
}.bind(_this), 50)
},
// 隐藏底部弹层
hideModal: function() {
var _this = this;
// 隐藏遮罩层
var animation = wx.createAnimation({
duration: 500,
timingFunction: "ease",
delay: 0
})
_this.animation = animation
animation.translateY(300).step()
_this.setData({
animationData: animation.export(),
})
setTimeout(function() {
animation.translateY(0).step()
_this.setData({
animationData: animation.export(),
showPop: false
})
}.bind(this), 200)
},
})

三步搞定!!上述代码配着小程序的官方文档来看,要理解它,难度应该不大。自己动手试试吧~~

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,118
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,590
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927