「小程序JAVA实战」小程序的组件(23)
转自:https://idig8.com/2018/08/11/xiaochengxu-chuji-23/
开始了解下小程序的组件。源码:https://github.com/limingios/wxProgram.git 中的No.10
组件
- 多个组件构成一张视图页面
>经过样式和布局,页面其实理解成html
- 组件包含<开始标签></结束标签>
每个组件都包含一些公用属性
官方的阐述
https://developers.weixin.qq.com/miniprogram/dev/component/

view视图组件
- view 组件
>用的最多的,也是之前的样例也讲过。https://developers.weixin.qq.com/miniprogram/dev/component/view.html

- 演示用例
<!--view.wxml-->
<!--手机按住1秒变成灰色,手指松开后2秒变回原来的红色-->
<view class="container" hover-class='hover-class' hover-start-time="10000" hover-stay-time="2000">
</view>
.container{
background-color: red;
}
.hover-class{
background-color: gray;
}

scroll-view 视图组件
- 官网的介绍
>https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html


- 演示
<!--scroll-view.wxml-->
<scroll-view class="container-wrapp" style='height:300rpx' scroll-y='true'
bindscrolltoupper="scrolltoupper"
bindscrolltolower="scrolltolower"
upper-threshold="0"
lower-threshold="0"
scroll-top="100"
enable-back-to-top="true"
scroll-with-animation="true"
bindscroll="scroll"
scroll-into-view="b"
>
<view id="a" class='sizeY a'>a</view>
<view id="b" class='sizeY b'>b</view>
<view id="c" class='sizeY c'>c</view>
<view id="d" class='sizeY d'>d</view>
<view id="e" class='sizeY e'>e</view>
</scroll-view>
<scroll-view class="container-nowrap" style='margin-top:250rpx' scroll-x='true' scroll-left="200">
<view id="a" class='sizeX a'>a</view>
<view id="b" class='sizeX b'>b</view>
<view id="c" class='sizeX c'>c</view>
<view id="d" class='sizeX d'>d</view>
<view id="e" class='sizeX e'>e</view>
</scroll-view>
//scroll-view.js
//获取应用实例
Page({
scrolltoupper:function(){
console.log("滚动到顶部");
},
scrolltolower:function(){
console.log("滚动到底部");
},
scroll:function(){
console.log("滚动中。。。");
}
})
.container-wrap{
display: flex;
flex-wrap:wrap;
}
.container-nowrap{
display:flex;
white-space: nowrap;
}
.sizeY{
width: 100%;
height: 150rpx;
}
.sizeX{
width: 250rpx;
height: 150px;
display: inline-block;
}
.a {
background: red;
}
.b {
background: yellow;
}
.c {
background: blue;
}
.d {
background: green;
}
.e {
background: gold;
}

注意:enable-back-to-top=”true” 在开发工具没办法演示只能在手机上才能演示出来点击直接到达顶部的效果。关于scrollview 只有横向和纵向,其实这块还是比较重要的多加练习吧。
swiper组件
- 俗称 轮播图
- 官方介绍
>https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html



- 演示
<!--swiper.wxml-->
<swiper indicator-dots="{{indicatorDots}}"
autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
<block wx:for="{{imgUrls}}">
<swiper-item>
<image src="{{item}}" class="slide-image" width="355" height="150"/>
</swiper-item>
</block>
</swiper>
<button bindtap="changeIndicatorDots"> indicator-dots </button>
<button bindtap="changeAutoplay"> autoplay </button>
<slider bindchange="intervalChange" show-value min="500" max="2000"/> interval
<slider bindchange="durationChange" show-value min="1000" max="10000"/> duration
//swiper.js
//获取应用实例
Page({
data: {
imgUrls: [
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
],
indicatorDots: false,
autoplay: false,
interval: 5000,
duration: 1000
},
changeIndicatorDots: function (e) {
this.setData({
indicatorDots: !this.data.indicatorDots
})
},
changeAutoplay: function (e) {
this.setData({
autoplay: !this.data.autoplay
})
},
intervalChange: function (e) {
this.setData({
interval: e.detail.value
})
},
durationChange: function (e) {
this.setData({
duration: e.detail.value
})
}
})


- 演示
<!--movable.wxml-->
<movable-area class="container">
<movable-view class='size' direction='all' inertia='true' out-of-bounds='true' x='50' y='50'
damping='100' friction='100' bindchange='onchange' bindscale='onscale' scale="true">
</movable-view>
</movable-area>
.container{
background-color: red;
width: 100%;
height: 650rpx;
}
.size{
background-color: yellow;
width: 300rpx;
height: 250rpx;
}
//movable.js
//获取应用实例
Page({
onchange:function(){
console.log("在移动。。");
},
onscale:function(){
console.log("在缩放")
}
})

PS:跟老铁一起过了一遍wx小程序关于视图的api,感觉还是组件很丰富,很好用!
「小程序JAVA实战」小程序的组件(23)的更多相关文章
- 「小程序JAVA实战」小程序首页视频(49)
转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...
- 「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 「小程序JAVA实战」小程序的举报功能开发(68)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...
- 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- 「小程序JAVA实战」小程序的视频点赞功能开发(62)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...
- 「小程序JAVA实战」小程序的springboot后台拦截器(61)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...
- 「小程序JAVA实战」小程序视频封面处理(48)
转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...
- 「小程序JAVA实战」小程序上传短视频(46)
转自:https://idig8.com/2018/09/14/xiaochengxujavashizhanxiaochengxushangchuanduanshipin45/ 个人信息:用户上传短视 ...
随机推荐
- python对文件的读写
文件 File 什么是文件 文件是用于数据存储和单位 文件通常用来长期存储数据 文件中的数据是以字节为单位进行顺序存储的 文件的操作流程: 1. 打开文件 2. 读/写文件 3. 关闭文件 注: 任何 ...
- 单独编译某个pas文件
默认的询问.提示.警告框都是英文,找到Vcl.consts.pas改了下,重新编译,放到安装目录下,替换原有的即可. 1. 使用dcc32.exe编译指定的pas文件,dcc32.exe所在目录见下图 ...
- lx 与cd 的计算方法
Candela to lux calculation with distance in meters The illuminance Ev in lux (lx) is equal to the lu ...
- html 添加flash标签 兼容firefox ie google
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" heig ...
- window.inner 兼容IE8
window.getHeight = function() { if (window.innerHeight != undefined) { return window.inn ...
- maven的介绍以及使用
maven的介绍以及使用 1.什么是maven maven是一个项目管理工具,一个依赖管理系统,maven通过项目对象模型来管理jar包(POM.xml文件) 2.maven的优点 1.maven使用 ...
- Distributed Denial of Service
Distributed Denial of Service https://www.cnblogs.com/163yun/p/10030890.html 全称Distributed Denial of ...
- lua不支持的泛型方法
1.没有泛型约束 2.缺少带约束的泛型参数 3.泛型约束必须为class /// <summary> /// 不支持生成lua的泛型方法(没有泛型约束) /// </summary& ...
- Django 向数据表中添加字段方法
在模型order中添加字段discount字段,并给予初始值0 方法: 先在models.py中修改模型 添加 discount = models.DecimalField(max_digits=8, ...
- c++ hook 钩子的使用介绍
转自:http://www.cnblogs.com/lidabo/archive/2012/11/29/2795269.html 例子:http://www.codeproject.com/Artic ...