小程序3

今天学习了小程序的组件,测试效果挺顺利的。下图是在手机上的效果图,性能数据那块灰色可以忽略。
在这里插入图片描述
三个代码文件也贴上
component.js

Page({
  data: {
     /* 轮播图 数据 */
    imgUrls: [
      '../images/banner1.jpg',
      '../images/banner2.jpg',
      '../images/banner3.jpg',
      '../images/banner4.jpg',
      '../images/banner5.jpg'
    ],
    indicatorDots: true, // 是否显示轮播图下面的圆点
    autoplay: true, // 轮播图是否自动播放
    interval: 3000, // 自动切换时间间隔
    duration: 1000, // 滑动时长

    /* 拖动效果 数据 */
    x: 5,
    y: 5,

     /* 覆盖效果 数据 */
    isplaying: true,

    /* 小程序图标 数据 */
    iconSize: [20, 30, 40, 50, 60, 70],
    iconColor: [
      'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
    ],
    iconType: [
      'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
    ]
  },
  
  // 进度条的形式改变interval的值
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },

  // 视频在页面加载时就需要创建
  onReady() {
    this.videoCtx = wx.createVideoContext('myVideo')
  },
  //点击切换暂停播放
  playorpause() {    
    if (this.data.isplaying) { //是播放中就调用暂停,是暂停就调用播放    
      this.pause(); // page里面调用函数要使用this关键词
    } else {      
      this.play();
    }
    //暂停或者播放后,值需要改反一下
    this.setData({
      isplaying: !this.data.isplaying
    })    
  },
  play() { //播放视频  
    this.videoCtx.play()
  },
  pause() { // 暂停视频    
    this.videoCtx.pause()
  }
})

component.wxss

/* pages/component/component.wxss */
.controls {
  position: relative;
  top: 50%;
  height: 50px;
  margin-top: -25px;
  display: flex;
}

.mvarea{
  height: 200px;
  width: 200px;
  background: black;
}
.mvview{
  height: 50px; 
  width: 50px; 
  background: white;
}


.play,.pause,.time {
  flex: 1;
  height: 100%;
}
.time {
  text-align: center;
  background-color: rgba(0, 0, 0, .2); /* 可以控制背景颜色透明度 */
  color: white;
  line-height: 50px;
}
.img {
  width: 40px;
  height: 40px;
  margin: 5px auto;
}

component.wxhl

<!-- swiper是滑动标签,比如轮播图。进度条等应用 -->
<view class="bold">轮播图效果</view>
<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>


<text>\n</text>
<view class="bold">进度条效果</view>
<view>自动切换时间间隔调整</view>
<!-- bindchange会返回一个detail参数到后台,后台接收获取detail里面的数据 -->
<slider bindchange="intervalChange" show-value min="500" max="2000"/> 
<!-- show-info表示右侧显示百分比,stroke-width设置线条宽度,color设置线条颜色,active线条是否有动态增长效果 -->
<progress percent="20" show-info stroke-width="10" color="red" active/>

<text>\n</text>
<view class="bold">拖动效果</view>
<view class="section">
  <view class="section_title">白色小块可以在黑色区域拖动</view>
  <movable-area class='mvarea'>
  <!-- movable-view必须被movable-area包裹,x和y的值表示白块的初始位置(原点是左上角),direction表示移动方向(all任意移动,vertical垂直,horizontal水平,none不能) -->
    <movable-view class='mvview' x="{{x}}" y="{{y}}" direction="all">
    </movable-view>
  </movable-area>  
</view>


<text>\n</text>
<view class="bold">覆盖效果:视频上打水印</view>
<video id="myVideo" autoplay='true' src="../videos/v.mp4" controls="{{false}}" event-model="bubble">
  <cover-view class="controls">
    <!-- 用一个图标覆盖在视频上,也可以做马赛克作用 -->
    <cover-view class="play" bindtap="playorpause">
      <cover-image class="img" src="{{isplaying?'../images/play.png':'../images/pause.jpg'}}" />
    </cover-view>    
    <!-- 纯文本覆盖在视频上,类似水印效果 -->
    <cover-view class="time">CCTV频道</cover-view>
  </cover-view>
</video>


<text>\n\n</text>
<view class="bold">小程序图标</view>
<view>图标的类型有以下一些,图标的大小和颜色通过icon标签里面的size和color控制</view>
<view>
  <block wx:for="{{iconType}}">
    <icon type="{{item}}" size="40"/>
  </block>
</view>

标签属性说明表,常用的属性已加粗显示
1、轮播图swiper标签

属性名类型默认值说明
indicator-dotsBooleanFALSE是否显示面板指示点
indicator-colorColorrgba(0, 0, 0, .3)指示点颜色
indicator-active-colorColor#000000当前选中的指示点颜色
autoplayBooleanFALSE是否自动切换
currentNumber0当前所在页面的 index
intervalNumber5000自动切换时间间隔
durationNumber500滑动动画时长
circularBooleanFALSE是否采用衔接滑动
verticalBooleanFALSE滑动方向是否为纵向
bindchangeEventHandlecurrent 改变时会触发 change 事件,event.detail = {current: current, source: source}

2、图标icon标签

属性名类型默认值说明
typeStringicon的类型,有效值:success, success_no_circle, info, warn, waiting, cancel, download, search, clear
sizeNumber23icon的大小,单位px
colorColoricon的颜色

3、进度条progress标签

属性名类型默认值说明
percentFloat百分比0~100
show-infoBooleanFALSE在进度条右侧显示百分比
stroke-widthNumber6进度条线的宽度,单位px
colorColor#09BB07进度条颜色 (请使用 activeColor)
activeColorColor已选择的进度条的颜色
backgroundColorColor未选择的进度条的颜色
activeBooleanFALSE进度条从左往右的动画
active-modeStringbackwardsbackwards: 动画从头播;forwards:动画从上次结束点接着播

4、拖动movable-area标签

属性名类型默认值说明
directionStringnonemovable-view的移动方向,属性值有all(任意)、vertical(仅可垂直移)、horizontal(仅可水平移)、none(不可移)
inertiaBooleanFALSEmovable-view是否带有惯性
out-of-boundsBooleanFALSE超过可移动区域后,movable-view是否还可以移动
xNumber定义x轴方向的偏移,如果x的值不在可移动范围内,会自动移动到可移动范围;改变x的值会触发动画
yNumber定义y轴方向的偏移,如果y的值不在可移动范围内,会自动移动到可移动范围;改变y的值会触发动画
dampingNumber20阻尼系数,用于控制x或y改变时的动画和过界回弹的动画,值越大移动越快
frictionNumber2摩擦系数,用于控制惯性滑动的动画,值越大摩擦力越大,滑动越快停止;必须大于0,否则会被设置成默认值

movable-area和movable-view标签若没设置width和height属性则默认为10px
cover-view可覆盖在map、video、canvas上,cover-view可以嵌套在cover-view里,这样嵌套是考虑样式布局稳定。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值