转自: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. DevExpress相关控件中非字符数值居左显示

    用了这么长时间的DevExpress控件,今天遇到俩问题. 一个是从头到尾看了一遍编译成功的例子,只能感慨,功能太丰富了,自己所用的不过是冰山一角.有些自己一直想实现的效果,原来早就有现成的可用,汗颜 ...

  2. Docker部署IPython

    本文的部署环境是Ubuntu 14.04 Docker Docker 详细概念可以去search,简单来说就是把应用打包到一个容器里的轻量级系统虚拟化服务 IPython Notebook IPyth ...

  3. MySQL性能指标计算方式

    -- 生成报告文件到/tmp目录中 tee /tmp/mysql_performance_stat.txt -- 统计性能指标前先开启下列参数,该参数使用IS数据库来存放数据库信息,由于使用PS库存放 ...

  4. 拷贝ssh公钥到多台服务器上

    这篇文章几乎是对Push SSH public keys to multiple host的翻译,谢谢该作者. 使用SSH登陆.执行命令到远程机器需要输入密码,很多系统需要免输密码访问远程机器,比如h ...

  5. Windows 10 四月更新,文件夹名称也能区分大小写?

    Windows 向来是不区分文件和文件夹大小写的,但是从 NTFS 开始却又支持区分文件夹大小写.而 Linux/Mac OS 一向都是区分文件和文件夹大小写的. 本文将推荐 Windows 10 四 ...

  6. pat甲级 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  7. MySQL中大数字加减,不产生千位符和科学计数

    mysql数字加减科学计数法 这两天因为需求,需要获取一张表的流水号.规则是这样的.当前日期+8位流水号.比如:2015062400000001,2015062400000002,2015062400 ...

  8. css 样式常用属性

    一般的一个DIV的CSS设置属性有:margin,padding,width,height,font-size,text-align,background,float,border 附:< cs ...

  9. UVA11401 Triangle Counting

    题意 输入\(n\),输出有多少种方法可以从\(1,2,3,\dots,n\)中选出3个不同的整数,使得以他们为三边长可以组成三角形. \(n \leq 10^6\) 分析 参照刘汝佳的题解. 按最大 ...

  10. (转)Tomcat迁移JBoss杂症—不识别及不能解析web.xml

    本文介绍了在将tomcat下的web工程迁移到jboss下面时遇到的问题 背景: Tomcat 7.0 JBoss AS 4.2.2 IED: Eclipse Java EE IDE for Web ...