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

先上图:

主要用到的微信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)
},
})

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

微信小程序——加入购物车弹层的更多相关文章

  1. 微信小程序之底部弹框预约插件

    代码地址如下:http://www.demodashi.com/demo/13982.html 一.前期准备工作: 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.c ...

  2. 微信小程序实战 购物车功能

    代码地址如下:http://www.demodashi.com/demo/12400.html 一.准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.com/ ...

  3. [转]微信小程序之购物车 —— 微信小程序实战商城系列(5)

    本文转自:http://blog.csdn.net/michael_ouyang/article/details/70755892 续上一篇的文章:微信小程序之商品属性分类  —— 微信小程序实战商城 ...

  4. 微信小程序之购物车功能

    前言 以往的购物车,基本都是通过大量的 DOM 操作来实现.微信小程序其实跟 vue.js 的用法非常像,接下来就看看小程序可以怎样实现购物车功能. 需求 先来弄清楚购物车的需求. 单选.全选和取消, ...

  5. 微信小程序笔记<七>视图层 —— wxml

    微信小程序的视图层由 *.wxml 组成,wxml与html一样属于标签语言,但wxml与html的标签截然不一样. xwml特性 一.数据绑定 <!--wxml--> <view& ...

  6. [转]微信小程序之购物车功能

    本文转自:https://www.cnblogs.com/linxin/p/6834206.html 前言 以往的购物车,基本都是通过大量的 DOM 操作来实现.微信小程序其实跟 vue.js 的用法 ...

  7. 【微信小程序】转载:微信小程序之购物车功能

    前言 以往的购物车,基本都是通过大量的 DOM 操作来实现.微信小程序其实跟 vue.js 的用法非常像,接下来就看看小程序可以怎样实现购物车功能. 需求 先来弄清楚购物车的需求. 单选.全选和取消, ...

  8. 微信小程序动画之弹出菜单

    用微信小程序做了一个动画,效果如上图: 代码: js: Page({ data: { isPopping: false, animPlus: {}, animCollect: {}, animTran ...

  9. 微信小程序开发-第一弹

    前言:       本篇文章为大家详细介绍微信小程序开发第一篇,后续步骤会逐步更新,欢迎大家关注. 第一步  注册        1.1 打开网址 https://mp.weixin.qq.com/  ...

随机推荐

  1. android辅助开发工具包介绍

    辅助开发工具包(ADK)是为硬件制造商和业余爱好者准备的参考实现.硬件制造商和业余爱好者可以使用此工具包作为开发Android辅助设备的起点.每一个ADK发行版都将提供源代码和硬件规格,以使整个辅助设 ...

  2. ASP.NET MVC中切换模板页(不同目录的cshtml文件)

    看来以后建立一个父类控制器还是有必要的... using System;using System.Collections.Generic;using System.Linq;using System. ...

  3. bug ,improvements, features jira等信息

    https://issues.apache.org/jira/secure/ReleaseNote.jspa?version=12341764&projectId=12315522 https ...

  4. 破解AI大脑黑盒迈出新一步!谷歌现在更懂机器,还开源了研究工具

    https://zhuanlan.zhihu.com/p/34306323 https://distill.pub/2018/building-blocks/

  5. oracle 负载均衡连接方式常用SQL语句备忘录

    1.---表中有重复记录用SQL语句查询出来 select * from Recharge where RechargeSerial in (select RechargeSerial from Re ...

  6. 18、利用 Windows Device Portal 获取用户闪退 dump

    当 uwp在用户的电脑上发生了闪退,并且由于用户距离较远,不便于使用 VS进行远程 Debug,更不可能让用户安装 Visual Studio进行分析的时候,在用户的电脑上收集 dump 是一种有效的 ...

  7. 【流媒体】UPnP的工作过程

    UPnP简介 通用即插即用(英语:Universal Plug and Play,简称UPnP)是由“通用即插即用论坛”(UPnP™ Forum)推广的一套网络协议. 该协议的目标是使家庭网络(数据共 ...

  8. Spring Boot Application 事件和监听器

    https://www.cnblogs.com/fdzfd/p/7872909.html ***************************************************** 一 ...

  9. LeetCode: Construct Binary Tree from Inorder and Postorder Traversal 解题报告

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

  10. LeetCode: Search a 2D Matrix 解题报告

    Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This m ...