写在前面

最近在负责一个微信小程序的前端以及前后端接口的对接的项目,整体上所有页面的布局我都已经搭建完成,里面有一些常用的特效,总结一下,希望对大家和我都能有所帮助

实例1:滚动tab选项卡

先看一下效果图吧,能够点击菜单或滑动页面切换,tab菜单部分可以实现左右滚动

好了,看一下我的源码吧!<喜欢的话拿走不谢哟>

1、wxml

  1. <!-- tab header -->
  2. <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}">
  3. <view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">全部</view>
  4. <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">营销系统</view>
  5. <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">家居建材</view>
  6. <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">美妆护肤</view>
  7. <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">数码电器</view>
  8. <view class="tab-item {{currentTab==5?'active':''}}" data-current="5" bindtap="swichNav">母婴玩具</view>
  9. <view class="tab-item {{currentTab==6?'active':''}}" data-current="6" bindtap="swichNav">零元购活动</view>
  10. </scroll-view>
  11. <!-- tab content -->
  12. <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab" style="max-height:{{winHeight}}rpx">
  13. <swiper-item wx:for="{{[0,1,2,3,4,5,6]}}">
  14. <scroll-view scroll-y="true" class="scoll-h">
  15. <block wx:for="{{[1,2,3,4,5,6,7]}}" wx:key="*this">
  16. <view class='goods-Wrapper'>
  17. <image mode='widthFix' class="goods-img" src='../../image/goods1.jpg'></image>
  18. <view class="goods-info">
  19. <view>周边团门店微营销系统年费</view>
  20. <view>
  21. <text class='price'>¥298.00</text>
  22. <text class='line-delete'>
  23. ¥298.00
  24. </text>
  25. <label>
  26. <button><image mode='widthFix' src='../../image/icon1.png'></image>1人团</button>
  27. <button><image mode='widthFix' src='../../image/icon2.png'></image>去开团</button>
  28. </label>
  29. </view>
  30. </view>
  31. </view>
  32. </block>
  33. </scroll-view>
  34. </swiper-item>
  35. </swiper>

okaychen

2、wxss <我只展示了tab菜单处的wxss,页面的样式就不在列出>

  1. .tab-h {
  2. height: 80rpx;
  3. width: 100%;
  4. box-sizing: border-box;
  5. overflow: hidden;
  6. line-height: 80rpx;
  7. background: #f7f7f7;
  8. font-size: 14px;
  9. white-space: nowrap;
  10. position: fixed;
  11. top:;
  12. left:;
  13. z-index:;
  14. }
  15.  
  16. .tab-item {
  17. margin: 0 36rpx;
  18. display: inline-block;
  19. }
  20.  
  21. .tab-item.active {
  22. color: #4675f9;
  23. position: relative;
  24. }
  25.  
  26. .tab-h .tab-item.active:after {
  27. content: "";
  28. display: block;
  29. height: 8rpx;
  30. width: 115rpx;
  31. background: #4675f9;
  32. position: absolute;
  33. bottom:;
  34. left: 5rpx;
  35. border-radius: 16rpx;
  36. }
  37.  
  38. .tab-h .tab-item:nth-child(1).active:after {
  39. width: 52rpx;
  40. }

okaychen

3、js

  1. var app = getApp();
  2. Page({
  3. data: {
  4. winHeight: "",//窗口高度
  5. currentTab: 0, //预设当前项的值
  6. scrollLeft: 0, //tab标题的滚动条位置
  7. expertList: [{ //假数据
  8. img: "",
  9. name: "",
  10. tag: "",
  11. answer: 134,
  12. listen: 2234
  13. }]
  14. },
  15. // 滚动切换标签样式
  16. switchTab: function (e) {
  17. this.setData({
  18. currentTab: e.detail.current
  19. });
  20. this.checkCor();
  21. },
  22. // 点击标题切换当前页时改变样式
  23. swichNav: function (e) {
  24. var cur = e.target.dataset.current;
  25. if (this.data.currentTaB == cur) { return false; }
  26. else {
  27. this.setData({
  28. currentTab: cur
  29. })
  30. }
  31. },
  32. //判断当前滚动超过一屏时,设置tab标题滚动条。
  33. checkCor: function () {
  34. if (this.data.currentTab > 4) {
  35. this.setData({
  36. scrollLeft: 300
  37. })
  38. } else {
  39. this.setData({
  40. scrollLeft: 0
  41. })
  42. }
  43. },
  44. onLoad: function () {
  45. var that = this;
  46. // 高度自适应
  47. wx.getSystemInfo({
  48. success: function (res) {
  49. var clientHeight = res.windowHeight,
  50. clientWidth = res.windowWidth,
  51. rpxR = 750 / clientWidth;
  52. var calc = clientHeight * rpxR - 180;
  53. console.log(calc)
  54. that.setData({
  55. winHeight: calc
  56. });
  57. }
  58. });
  59. },
  60. footerTap: app.footerTap
  61. })

okaychen

实例2:星级评分

按照惯例先上效果图,默认一星,点击可以选择星级,可半星显示。

1、wxml

  1. <view class='accessWrapper'>
  2. <view class='title'>
  3. 评价
  4. <view class='starsWrapper'>
  5. <block wx:for="{{stars}}">
  6. <image class="star-image" style="left: {{item*50}}rpx" src="{{key > item ?(key-item == 0.5?halfSrc:selectedSrc) : normalSrc}}">
  7. <view class="item" style="left:0rpx" data-key="{{item+0.5}}" bindtap="selectLeft"></view>
  8. <view class="item" style="left:25rpx" data-key="{{item+1}}" bindtap="selectRight"></view>
  9. </image>
  10. </block>
  11. </view>
  12. </view>
  13.  
  14. <!-- 这里绑定是bindInput而不是bindtab -->
  15. <textarea bindinput='textAreaCon' placeholder='写点什么吧...' auto-focus='true'></textarea>
  16. <view class='uploadFile' bindtap='upload'>+</view>
  17. </view>
  18.  
  19. <button type='submit' bindtap='saveAccess' class='save-edit'>提交保存</button>

okaychen

2、wxss

  1. page{
  2. background: #f5f5f5;
  3. }
  4.  
  5. .accessWrapper{
  6. background: #fff;
  7. font-size: 14px;
  8. padding-bottom: 10px;
  9. }
  10.  
  11. .accessWrapper textarea{
  12. width: 94%;
  13. margin: 0 auto;
  14. max-height: 200px;
  15. border-top: 1px solid #f5f5f5;
  16. padding: 10px 0px;
  17. }
  18.  
  19. .accessWrapper textarea::-webkit-scrollbar{
  20. width: 0px;
  21. height: 0px;
  22. color: transparent;
  23. }
  24.  
  25. .accessWrapper .title{
  26. padding: 10px;
  27. }
  28. .starsWrapper{
  29. position: absolute;
  30. top: -20px;
  31. right: 135px;
  32. }
  33. /* stars */
  34. .star-image {
  35. position: absolute;
  36. top: 50rpx;
  37. width: 50rpx;
  38. height: 50rpx;
  39. src: "../../../image/normal.png";
  40. }
  41.  
  42. .item {
  43. position: absolute;
  44. top: 0rpx;
  45. width: 50rpx;
  46. height: 50rpx;
  47. }
  48.  
  49. .uploadFile{
  50. width: 50px;
  51. height: 50px;
  52. border: 1px solid #f5f5f5;
  53. color: #999;
  54. text-align: center;
  55. line-height: 50px;
  56. font-size: 20px;
  57. margin-left: 10px;
  58. }

okaychen

3、js

  1. var app = getApp()
  2. Page({
  3. data: {
  4. stars: [0, 1, 2, 3, 4],
  5. normalSrc: '../../../image/normal.png',
  6. selectedSrc: '../../../image/selected.png',
  7. halfSrc: '../../../image/half.png',
  8. key: 1,//评分
  9. path: ' ',
  10. userInput:' '
  11. },
  12. onLoad: function () {
  13.  
  14. },
  15.  
  16. //点击右边,半颗星
  17. selectLeft: function (e) {
  18. var key = e.currentTarget.dataset.key
  19. if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
  20. //只有一颗星的时候,再次点击,变为0颗
  21. key = 0;
  22. }
  23. console.log("得" + key + "分")
  24. this.setData({
  25. key: key
  26. })
  27.  
  28. },
  29. //点击左边,整颗星
  30. selectRight: function (e) {
  31. var key = e.currentTarget.dataset.key
  32. console.log("得" + key + "分")
  33. this.setData({
  34. key: key
  35. })
  36. },
  37.  
  38. upload: function () {
  39. var that = this
  40. wx.chooseImage({
  41. count: 1,
  42. sizeType: ['original', 'compressed'],
  43. sourceType: ['album', 'camera'],
  44. success: function (res) {
  45. var tempFilePaths = res.tempFilePaths
  46. console.log(tempFilePaths)
  47. wx.uploadFile({
  48. url: 'http://example.weixin.qq.com/upload',
  49. filePath: tempFilePaths[0],
  50. name: 'file',
  51. formData: {
  52. 'user': 'test'
  53. },
  54. success: function (res) {
  55. var data = res.data
  56. wx.showModal({
  57. title: '上传文件返回状态',
  58. content: '成功',
  59. success: function (res) {
  60. if (res.confirm) {
  61. console.log('用户点击确定')
  62. }
  63. }
  64. }) //do something
  65. },
  66. fail: function (res) {
  67. console.log(res)
  68. }
  69. })
  70. that.setData({
  71. path: tempFilePaths
  72. })
  73. }
  74. })
  75. },
  76.  
  77. textAreaCon:function(e){
  78. var that = this;
  79. that.setData({
  80. userInput: e.detail.value,
  81. })
  82. },
  83. saveAccess:function(e){
  84. if(this.data.userInput == ' '){
  85. wx.showModal({
  86. title: '提示',
  87. content: '对不起,请输入留言内容',
  88. })
  89. }else{
  90. console.log(this.data.userInput);
  91. // 成功监听用户输入内容
  92.  
  93. }
  94. }
  95.  
  96. })

okaychen

实例3:自定义底部弹出层

自定义底部弹出层,在电商的小程序中经常会用到,根据需要自定义弹出内容,先看下我的效果

我已经把我自定义的部分抽离了出来

1、wxml

  1. <view class='yourPurse' bindtap='showModal1'></view>
  2.  
  3. <view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view>
  4. <view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{showModalStatus}}"></view>

okaychen

2、wxss

  1. .commodity_screen {
  2. width: 100%;
  3. height: 100%;
  4. position: fixed;
  5. top:;
  6. left:;
  7. background: #000;
  8. opacity: 0.2;
  9. overflow: hidden;
  10. z-index:;
  11. color: #fff;
  12. }
  13.  
  14. .commodity_attr_box {
  15. width: 100%;
  16. overflow: hidden;
  17. position: fixed;
  18. bottom:;
  19. left:;
  20. z-index:;
  21. background: #fff;
  22. padding-top: 20rpx;
  23. }

okaychen

3、js

  1. showModal: function () {
  2. // 显示遮罩层
  3. var animation = wx.createAnimation({
  4. duration: 200,
  5. timingFunction: "linear",
  6. delay: 0
  7. })
  8. this.animation = animation
  9. animation.translateY(300).step()
  10. this.setData({
  11. animationData: animation.export(),
  12. showModalStatus: true
  13. })
  14. setTimeout(function () {
  15. animation.translateY(0).step()
  16. this.setData({
  17. animationData: animation.export()
  18. })
  19. }.bind(this), 200)
  20. },
  21. hideModal: function () {
  22. // 隐藏遮罩层
  23. var animation = wx.createAnimation({
  24. duration: 200,
  25. timingFunction: "linear",
  26. delay: 0
  27. })
  28. this.animation = animation
  29. animation.translateY(300).step()
  30. this.setData({
  31. animationData: animation.export(),
  32. })
  33. setTimeout(function () {
  34. animation.translateY(0).step()
  35. this.setData({
  36. animationData: animation.export(),
  37. showModalStatus: false
  38. })
  39. }.bind(this), 200)
  40. }

okaychen

写在后面

这次没有文字化的知识点,是我正在做的小程序项目中我做的一些小实例的源码,总结下来了三个非常常用的,

喜欢或者对你有帮助的话欢迎copy和学习,

另外这个项目最近在github上持续更新,欢迎star和在博客中留下你的建议。想要什么特效在下面留言博主也会尽力满足各位客官.

最后祝大家国庆节快乐(#^.^#)

微信小程序实现各种特效实例的更多相关文章

  1. 【小程序】微信小程序实现各种特效实例

    写在前面 最近在负责一个微信小程序的前端以及前后端接口的对接的项目,整体上所有页面的布局我都已经搭建完成,里面有一些常用的特效,总结一下,希望对大家和我都能有所帮助 实例1:滚动tab选项卡 先看一下 ...

  2. ES6中Class的用法及在微信小程序中的应用实例

    1.ES6的基本用法 ES6 提供了更接近传统语言的写法,引入了 Class(类)这个概念,作为对象的模板.通过class关键字,可以定义类.基本上,ES6 的class可以看作只是一个语法糖,它的绝 ...

  3. 微信小程序侧边栏滑动特效(左右滑动)

    侧边栏滑动是很常见的功能,但是小程序出来不久,很多特效还没有成熟案例,只能原生重写,所以今天为大家带来4个漂亮的侧边栏特效~~ 侧边栏特效一 先看效果: wxml: <!--page/one/i ...

  4. 微信小程序之登录页实例

    项目效果图: 目录结构: login.wxml: <view class="container"> <view class="login-icon&qu ...

  5. 微信小程序开发--常用开发实例

    一.常用商品列表的换行排布 <view class="box_max"> <view class="box_min">限时秒杀</ ...

  6. 【微信小程序】调用wx.request接口需要注意的问题

    写在前面 之前写了一篇<微信小程序实现各种特效实例>,上次的小程序的项目我负责大部分前端后台接口的对接,然后学长帮我改了一些问题.总的来说,收获了不少吧! 现在项目已经完成,还是要陆陆续续 ...

  7. 微信小程序与AspNetCore SignalR聊天实例

    微信小程序与aspnetcore signalr实例 本文不对小程序与signalr做任何介绍,默认读者已经掌握 aspnetcore Signalr文档 小程序文档 写在之前 SignalR没有提供 ...

  8. [转]微信小程序之加载更多(分页加载)实例 —— 微信小程序实战系列(2)

    本文转自;http://blog.csdn.net/michael_ouyang/article/details/56846185 loadmore 加载更多(分页加载) 当用户打开一个页面时,假设后 ...

  9. 微信小程序学习指南

    作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

随机推荐

  1. SQL Server中怎么查看每个数据库的日志大小,以及怎么确定数据库的日志文件,怎么用语句收缩日志文件

    一,找到每个数据库的日志文件大小 SQL Server:查看SQL日志文件大小命令:dbcc sqlperf(logspace) DBA 日常管理工作中,很重要一项工作就是监视数据库文件大小,及日志文 ...

  2. 微信小程序里使用阿里巴巴矢量图标

    登录 阿里巴巴矢量图标 (https://www.iconfont.cn) 选中图标,加入购物车图标 下载源代码 解析出来如下文件结构 有两种使用方式: 1)不转换成base64的文件 找到 icon ...

  3. November 03rd, 2017 Week 44th Friday

    The secret of success is to do the common things uncommonly well. 成功的秘诀就是把平凡的事情做得异常的好. Sometimes you ...

  4. [LOJ 2720][BZOJ 5417][UOJ 395][NOI 2018]你的名字

    [LOJ 2720][BZOJ 5417][UOJ 395][NOI 2018]你的名字 题意 给定一个大串 \(S\) 以及 \(q\) 次询问, 每次询问给定一个串 \(T\) 和区间 \([l, ...

  5. SDN2017 第五次实验作业

    实验目的 1.搭建如下拓扑并连接控制器 2.下发相关流表和组表实现负载均衡 3.抓包分析验证负载均衡 实验步骤 建立以下拓扑,并连接上ODL控制器. 利用ODL下发组表.流表,实现建议负载均衡 s1组 ...

  6. FIO_工具_专业

    一.FIO工具安装: 1.查看fio是否安装 [root@localhost /]#rpm –qa|grep fio 2.源码安装(推荐) 官网地址:http://freecode.com/proje ...

  7. ArcGIS API for Javascript之专题图的制作(四)热力图渲染(上)

    一 .热力图定义 热力图(heat map)也称热图,是以特殊颜色高亮区域的形式表示密度.温度.气压.频率等分布的不易理解和表达的数据. 二.HeatmapRenderer esri/renderer ...

  8. MySQL安装及初步配置.md

    MySQL 安装脚本 #!/bin/bash MYSQL_BASEDIR=/usr/local/mysql MySQL_DATADIR=/data/mysql SERVER_ID=`hostname ...

  9. Swift: Associated Types--为什么协议使用关联类型而不是泛型

    关联类型的形式为类型的引用进而进行约束提供了条件: 同时能够简化语法形式. Swift: Associated Types http://www.russbishop.net/swift-associ ...

  10. docker swarm英文文档学习-4-swarm模式如何运行

    1)How nodes work Docker引擎1.12引入了集群模式,使你能够创建一个由一个或多个Docker引擎组成的集群,称为集群.集群由一个或多个节点组成:在群模式下运行Docker引擎1. ...