转自: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)的更多相关文章

  1. 「小程序JAVA实战」小程序首页视频(49)

    转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...

  2. 「小程序JAVA实战」小程序的flex布局(22)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...

  3. 「小程序JAVA实战」小程序的留言和评价功能(70)

    转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...

  4. 「小程序JAVA实战」小程序的举报功能开发(68)

    转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...

  5. 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...

  6. 「小程序JAVA实战」小程序的关注功能(65)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...

  7. 「小程序JAVA实战」小程序的视频点赞功能开发(62)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...

  8. 「小程序JAVA实战」小程序的springboot后台拦截器(61)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...

  9. 「小程序JAVA实战」小程序视频封面处理(48)

    转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...

  10. 「小程序JAVA实战」小程序上传短视频(46)

    转自:https://idig8.com/2018/09/14/xiaochengxujavashizhanxiaochengxushangchuanduanshipin45/ 个人信息:用户上传短视 ...

随机推荐

  1. 【视觉控】3D时钟

    心心念念的新年过完了~却没念到年会,更没念到年终奖~哎,以任何理由不发年终奖的公司都是臭流氓~然,我们公司没有理由,压根儿就没提这事,哇卡卡卡卡!!! ======================== ...

  2. 设置checkbox不能选中,复选框不能选中

    Web开发:设置复选框的只读效果 在Web开发中,有时候需要显示一些复选框(checkbox),表明这个地方是可以进行勾选操作的,但是有时候是只想告知用户"这个地方是可以进行勾选操作的&qu ...

  3. linux自学(九)之开始centos学习,安装数据库MariaDB

    上一篇:linux自学(八)之开始centos学习,安装tomcat 数据库我们不安装mysql,我网上看了好多资料发现mysql安装比较麻烦,我们这里安装同一个父亲的产品MariaDB.驱动,端口等 ...

  4. 每天一个linux命令:【转载】cd命令

    Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. 所以,学习Linux 常用命令,首先就要学好 cd 命令的使用方法技巧. 1.  ...

  5. <context:annotation-config/>,<context:component-scan/>,<mvc:annotation-driven/>区分

    链接:http://blog.csdn.net/baple/article/details/16864175 链接:http://blog.csdn.net/Baple/article/details ...

  6. Backward Digit Sums

    FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N < ...

  7. [LOJ6261]一个人的高三楼

    loj description 给你一个长度为\(n\)的数列\(a_i\),求它的\(k\)次前缀和模\(998244353\).(就是做\(k\)次前缀和后的数列) \(n\le10^5,k\le ...

  8. C语言控制台窗体图形界面编程(八):鼠标事件

           上次讲的是键盘事件,这次我们介绍鼠标事件. 以下先介绍下鼠标事件的结构体以及相关信息. typedef struct _MOUSE_EVENT_RECORD //鼠标事件结构体 { CO ...

  9. 在Mac和win7上分别安装了docker后,发现原来的vagrant都启动不了了

    在Mac和win7上分别安装了docker后,发现原来的vagrant都启动不了了 liugx@liugx vagrant$ vagrant up /opt/vagrant/embedded/gems ...

  10. 工业标准接口OPC Server

    工业标准接口OPC  Server OPC Server服务器软件,简称OPCServer,是针对企业生产过程中所涉及到的各种DCS.PLC.组态软件.电力综合自动化等控制系统.测量系统.其它辅助生产 ...