写在前面

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

实例1:滚动tab选项卡

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

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

1、wxml

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

okaychen

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

.tab-h {
height: 80rpx;
width: 100%;
box-sizing: border-box;
overflow: hidden;
line-height: 80rpx;
background: #f7f7f7;
font-size: 14px;
white-space: nowrap;
position: fixed;
top:;
left:;
z-index:;
} .tab-item {
margin: 0 36rpx;
display: inline-block;
} .tab-item.active {
color: #4675f9;
position: relative;
} .tab-h .tab-item.active:after {
content: "";
display: block;
height: 8rpx;
width: 115rpx;
background: #4675f9;
position: absolute;
bottom:;
left: 5rpx;
border-radius: 16rpx;
} .tab-h .tab-item:nth-child(1).active:after {
width: 52rpx;
}

okaychen

3、js

var app = getApp();
Page({
data: {
winHeight: "",//窗口高度
currentTab: 0, //预设当前项的值
scrollLeft: 0, //tab标题的滚动条位置
expertList: [{ //假数据
img: "",
name: "",
tag: "",
answer: 134,
listen: 2234
}]
},
// 滚动切换标签样式
switchTab: function (e) {
this.setData({
currentTab: e.detail.current
});
this.checkCor();
},
// 点击标题切换当前页时改变样式
swichNav: function (e) {
var cur = e.target.dataset.current;
if (this.data.currentTaB == cur) { return false; }
else {
this.setData({
currentTab: cur
})
}
},
//判断当前滚动超过一屏时,设置tab标题滚动条。
checkCor: function () {
if (this.data.currentTab > 4) {
this.setData({
scrollLeft: 300
})
} else {
this.setData({
scrollLeft: 0
})
}
},
onLoad: function () {
var that = this;
// 高度自适应
wx.getSystemInfo({
success: function (res) {
var clientHeight = res.windowHeight,
clientWidth = res.windowWidth,
rpxR = 750 / clientWidth;
var calc = clientHeight * rpxR - 180;
console.log(calc)
that.setData({
winHeight: calc
});
}
});
},
footerTap: app.footerTap
})

okaychen

实例2:星级评分

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

1、wxml

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

okaychen

2、wxss

page{
background: #f5f5f5;
} .accessWrapper{
background: #fff;
font-size: 14px;
padding-bottom: 10px;
} .accessWrapper textarea{
width: 94%;
margin: 0 auto;
max-height: 200px;
border-top: 1px solid #f5f5f5;
padding: 10px 0px;
} .accessWrapper textarea::-webkit-scrollbar{
width: 0px;
height: 0px;
color: transparent;
} .accessWrapper .title{
padding: 10px;
}
.starsWrapper{
position: absolute;
top: -20px;
right: 135px;
}
/* stars */
.star-image {
position: absolute;
top: 50rpx;
width: 50rpx;
height: 50rpx;
src: "../../../image/normal.png";
} .item {
position: absolute;
top: 0rpx;
width: 50rpx;
height: 50rpx;
} .uploadFile{
width: 50px;
height: 50px;
border: 1px solid #f5f5f5;
color: #999;
text-align: center;
line-height: 50px;
font-size: 20px;
margin-left: 10px;
}

okaychen

3、js

var app = getApp()
Page({
data: {
stars: [0, 1, 2, 3, 4],
normalSrc: '../../../image/normal.png',
selectedSrc: '../../../image/selected.png',
halfSrc: '../../../image/half.png',
key: 1,//评分
path: ' ',
userInput:' '
},
onLoad: function () { }, //点击右边,半颗星
selectLeft: function (e) {
var key = e.currentTarget.dataset.key
if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
//只有一颗星的时候,再次点击,变为0颗
key = 0;
}
console.log("得" + key + "分")
this.setData({
key: key
}) },
//点击左边,整颗星
selectRight: function (e) {
var key = e.currentTarget.dataset.key
console.log("得" + key + "分")
this.setData({
key: key
})
}, upload: function () {
var that = this
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var tempFilePaths = res.tempFilePaths
console.log(tempFilePaths)
wx.uploadFile({
url: 'http://example.weixin.qq.com/upload',
filePath: tempFilePaths[0],
name: 'file',
formData: {
'user': 'test'
},
success: function (res) {
var data = res.data
wx.showModal({
title: '上传文件返回状态',
content: '成功',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
}) //do something
},
fail: function (res) {
console.log(res)
}
})
that.setData({
path: tempFilePaths
})
}
})
}, textAreaCon:function(e){
var that = this;
that.setData({
userInput: e.detail.value,
})
},
saveAccess:function(e){
if(this.data.userInput == ' '){
wx.showModal({
title: '提示',
content: '对不起,请输入留言内容',
})
}else{
console.log(this.data.userInput);
// 成功监听用户输入内容 }
} })

okaychen

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

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

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

1、wxml

<view class='yourPurse' bindtap='showModal1'></view>

<view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view>
<view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{showModalStatus}}"></view>

okaychen

2、wxss

.commodity_screen {
width: 100%;
height: 100%;
position: fixed;
top:;
left:;
background: #000;
opacity: 0.2;
overflow: hidden;
z-index:;
color: #fff;
} .commodity_attr_box {
width: 100%;
overflow: hidden;
position: fixed;
bottom:;
left:;
z-index:;
background: #fff;
padding-top: 20rpx;
}

okaychen

3、js

showModal: function () {
// 显示遮罩层
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.translateY(300).step()
this.setData({
animationData: animation.export(),
showModalStatus: true
})
setTimeout(function () {
animation.translateY(0).step()
this.setData({
animationData: animation.export()
})
}.bind(this), 200)
},
hideModal: function () {
// 隐藏遮罩层
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
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(),
showModalStatus: false
})
}.bind(this), 200)
}

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. 【SPL标准库专题(8)】 Datastructures:SplFixedArray

    SplFixedArray主要是处理数组相关的主要功能,与普通php array不同的是,它是固定长度的,且以数字为键名的数组,优势就是比普通的数组处理更快. 类摘要 SplFixedArray im ...

  2. 使用Amanda ZRM备份远程MySQL数据库

    本文写道最后的时候,我才发现ZRM for MySQL的一个致命问题,就我目前的理解和测试来看,它恢复数据的时候是采取覆盖的方式,举个例子,假定某台数据库服务器上有两个数据库test1,test2,你 ...

  3. python爬虫_入门_翻页

    写出来的爬虫,肯定不能只在一个页面爬,只要要爬几个页面,甚至一个网站,这时候就需要用到翻页了 其实翻页很简单,还是这个页面http://bbs.fengniao.com/forum/10384633. ...

  4. python基础学习6----字符串操作

    一.重复输出字符串 print('hello'*20)#输出20个hello 二.通过索引获取字符串中字符 print('helloworld'[2:])#输出lloworld 三.关键字 in pr ...

  5. Linux命令网络命令之netstat

    Linux命令网络命令之netstat 这一年感觉到技术上成长到了一个瓶颈.可能是感觉自己学的东西足够应付目前的工作了,因此精神上就产生了懈怠,不思进取.到了一个技术氛围不错的公司,有许多专业能力很不 ...

  6. IE 8 下sharepoint 2013 难看的字体的解决方案

    将 corev15.css 中的有关"Segoe UI","Segoe",Tahoma,移除即可. 一共二处 C:\Program Files\Common F ...

  7. [Python3]subprocess.check_output() 在python3的输出为bytes而非string,在实际使用过程中得增加一个解码过程decode(),不然会有问题

    按以往python2的习惯编码输出报错 #-*- coding:utf-8 -*- ''' Created on 2018年7月21日 @author: lenovo ''' import os im ...

  8. 【adb命令】在cmd窗口中使用adb install命令安装 中文名字apk报错的解决办法

    1.在cmd窗口中使用adb install命令安装中文名字apk报错,安装英文名字apk就正常,详细报错如下图: 2.查看adb版本号:adb version 3.怀疑是adb版本的原因,尝试换个最 ...

  9. animate is not a function(zepto 使用报错)[转]

    animate is not a function(zepto 使用报错) 1.为什么使用zepto写animate报错? 因为zepto默认构建包含: Core, Ajax, Event, Form ...

  10. jsp泛型支持

    今天在使用idea做练习时,某个jsp页面报错如下: '<>'operator is not allowed for source level below 1.7 出错代码如下: Map& ...