转自: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. 如何将局域网中的 windows 硬盘挂载到 linux 系统中

    1.共享windows上的E盘 2.linux上执行 mount //192.168.3.181/e /tmp/test -o username=dell,,password=abcdef 3.保证两 ...

  2. BZOJ4033 HAOI2015 树上染色 【树上背包】

    BZOJ4033 HAOI2015 树上染色 Description 有一棵点数为N的树,树边有边权.给你一个在0~N之内的正整数K,你要在这棵树中选择K个点,将其染成黑色,并将其他的N-K个点染成白 ...

  3. 在 GitHub 公开仓库中隐藏自己的私人邮箱地址

    GitHub 重点在开方源代码,其本身还是非常注重隐私的.这一点与面向企业的 GitLab 很不一样. 不过,你依然可能在 GitHub 上泄露隐私信息,例如企业内部所用的电子邮箱. GitHub 对 ...

  4. ios 视图切换翻页效果

    本文写的是视图切换,涉及到的内容有 1.实现代码添加Navigation Bar  Toolbal: 2.实现在Navigation Bar和Toolbar上用代码添加Bar Button Item: ...

  5. 《DSP using MATLAB》示例Example 6.9

    代码: % All-Pole IIR filter to Lattice structure filter a = [1, 13/24, 5/8, 1/3]; K = dir2latc(a) % To ...

  6. 《DSP using MATLAB》示例Example7.14

    代码: M = 20; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; Hrs = [1, 1, 1, zeros(1, 15), 1, 1]; % Idea ...

  7. 【java基础】java中Object对象中的Hashcode方法的作用

    以下是关于HashCode的官方文档定义: hashcode方法返回该对象的哈希码值.支持该方法是为哈希表提供一些优点,例如,java.util.Hashtable 提供的哈希表. hashCode  ...

  8. Youtube 视频下载

    Youtube 视频下载 由于特殊原因,需要下载 Youtube 的视频. https://www.clipconverter.cc/

  9. [嵌入式]I2C协议指东

    最近闲来无聊,入了一块MPU6050,手头本来就有一块原子的STM32 MINI开发板,凑活着学习了一下IIC,特此总结. IIC,是集成电路总线[Inter-Intergrated Circuit] ...

  10. 【转】如何将FLAC格式转为MP3格式

    原文网址:http://jingyan.baidu.com/ae/3aed632e65708470108091ca.html FLAC全称为无损音频压缩编码,FLAC格式又称无损格式 不会破坏原有的音 ...