【微信小程序 swiper swiper-item】

作者 : admin 本文共2077个字,预计阅读时间需要6分钟 发布时间: 2024-06-10 共1人阅读

用swiper与swiper-item做轮播

【轮播效果】
【微信小程序 swiper swiper-item】插图

代码:

	<swiper class="swiper-container">
	  <swiper-item>
	    <view class="item">A</view>
	  </swiper-item>
	  <swiper-item>
	    <view class="item">B</view>
	  </swiper-item>
	  <swiper-item>
	    <view class="item">C</view>
	  </swiper-item>
	</swiper>

样式

	.swiper-container {
	  height: 150px;
	}
	.item{
	  height: 100%;
	  text-align: center;
	  line-height: 150px;
	}
	swiper-item:nth-child(1) .item{
	  background-color: pink;
	}
	swiper-item:nth-child(2) .item{
	  background-color: red;
	}
	swiper-item:nth-child(3) .item{
	  background-color: gold;
	}

swiper当中常用的属性

  1. indicator-dots boolean false 是否显示面板指示点
  2. indicator-color color rgba(0, 0, 0,.3) 指示点颜色
  3. indicator-active-color color false 当前选中的指示点颜色
  4. autoplay boolean false 是否自动切换 interval number 5000 自动切换时间间隔
  5. circular boolean false 是否采用衔接滑动
  6. 属性名 indicator-dots
	<swiper class="swiper-container" 
	indicator-dots 
	indicator-color="#fff" 
	indicator-active-color="red" 
	autoplay interval="2000" 
	circular>
	  <swiper-item>
	    <view class="item">A</view>
	  </swiper-item>
	  <swiper-item>
	    <view class="item">B</view>
	  </swiper-item>
	  <swiper-item>
	    <view class="item">C</view>
	  </swiper-item>
	</swiper>

视频 发送弹幕

【发送弹幕效果】

【微信小程序 swiper swiper-item】插图(1)

先引入官方视频连接
http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023hy=SHfileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400

Xxx.wxml

	<!-- 弹幕小案例 -->
	<view>
	<!-- 视频 -->
	  <video
	  id="vi"
	  danmu-list="{{danmuList}}"
	  style="width: 100%;"
	  src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023hy=SHfileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400"/>
	</view>
	<!-- 发送弹幕 -->
	<view style="border: 1rpx solid;">
	  <!-- model 双向绑定 -->
	  <input model:value="{{danmuVal}}" type="text"/>
	</view>
	<button bind:tap="sendDanmu">发送弹幕</button>

Xxx.js

Page({
  data:{
    danmuList:[
      // 颜色 时间 文本
      {color:'red',time:1,text:'第一个弹幕'}
    ],
    danmuVal:""
  },
  onReady(){
    // 创建video上下文
    this.videoContext = wx.createVideoContext('vi')
  },
  // 点击发送弹幕
  sendDanmu(){
    // 调用video上下文的sendDanmu方法
    this.videoContext.sendDanmu({
      text:this.data.danmuVal,
      color:'pink'
    })
  }
})

本站无任何商业行为
个人在线分享-虚灵IT资料分享 » 【微信小程序 swiper swiper-item】
E-->