前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >「小程序JAVA实战」小程序的视图组件(23)

「小程序JAVA实战」小程序的视图组件(23)

作者头像
IT架构圈
发布2018-12-25 09:57:17
7920
发布2018-12-25 09:57:17
举报
文章被收录于专栏:IT架构圈IT架构圈

开始了解下小程序的组件。源码: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

  • 演示用例
代码语言:javascript
复制
<!--view.wxml-->

<!--手机按住1秒变成灰色,手指松开后2秒变回原来的红色-->
<view class="container" hover-class='hover-class' hover-start-time="10000" hover-stay-time="2000">
</view>
代码语言:javascript
复制
.container{
  background-color: red;
}

.hover-class{
  background-color: gray;
}
scroll-view 视图组件
  • 官网的介绍

https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html

  • 演示
代码语言:javascript
复制
<!--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>
代码语言:javascript
复制
//scroll-view.js
//获取应用实例

Page({
  scrolltoupper:function(){
      console.log("滚动到顶部");
  },
  scrolltolower:function(){
      console.log("滚动到底部");
  },
  scroll:function(){
    console.log("滚动中。。。");
  }

})
代码语言:javascript
复制
.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

  • 演示
代码语言:javascript
复制
<!--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
代码语言:javascript
复制
//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
    })
  }
})
  • 演示
代码语言:javascript
复制
<!--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>
代码语言:javascript
复制
.container{
  background-color: red;
  width: 100%;
  height: 650rpx;
}

.size{
  background-color: yellow;
  width: 300rpx;
  height: 250rpx;
}
代码语言:javascript
复制
//movable.js
//获取应用实例

Page({
  onchange:function(){
    console.log("在移动。。");
  },
  onscale:function(){
    console.log("在缩放")
  }
})

PS:跟老铁一起过了一遍wx小程序关于视图的api,感觉还是组件很丰富,很好用!

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-12-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 编程坑太多 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 视图组件
    • view视图组件
      • scroll-view 视图组件
        • swiper组件
        相关产品与服务
        云开发 CloudBase
        云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档