swiper (滑动图片加文字)
滑块视图容器,常用于走马灯、轮播图
注意:由于铺满整行使用的是 widthFix(宽度不变高度裁剪),在进行圆角设置的时候左下角和右下角可能会失败。
在 Taro 文件中引入组件
import { Swiper, SwiperItem } from '@tarojs/components'
import Taro, { Component } from '@tarojs/taro'// 引入 Swiper, SwiperItem 组件import { Swiper, SwiperItem } from '@tarojs/components'class App extends Components {render () {return (<View className='at-row '><View className='at-col border'><Swiper className='test-h' indicatorColor='#999' indicatorActiveColor='#333' circular indicatorDots ><SwiperItem><View className='demo-text-1'><Image className='lm' src='http://placekitten.com/900/900' mode='widthFix'></Image><Text className='child'>child </Text></View></SwiperItem><SwiperItem><View className='demo-text-2'><Image className='lm' src='http://placekitten.com/700/700' mode='widthFix'></Image><Text className='child'>child </Text></View></SwiperItem><SwiperItem><View className='demo-text-3'><Image className='lm' src='http://placekitten.com/900/900' mode='widthFix'></Image><Text className='child'>child </Text></View></SwiperItem></Swiper></View></View>)}}
CSS
.border {box-shadow:0 6rpx 6rpx 6rpx lightgray;border-radius:5%;margin-left: 15rpx;margin-right: 15rpx;margin-bottom: 25rpx;}.lm {box-shadow:0 3rpx 5rpx 1rpx lightgray;border-radius:5%;padding-right: 10rpx;margin-left: 20rpx;width: 95%;}
参数
| 微信 | H5 | 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|---|---|
| √ | √ | indicatorDots | 是否显示面板指示点 | Boolean | - | false |
| √ | √ | indicatorColor | 指示点颜色 | String | - | rgba(0, 0, 0, .3) |
| √ | √ | indicatorActiveColor | 当前选中的指示点颜色 | String | - | 000 |
| √ | √ | autoplay | 是否自动切换 | Boolean | - | false |
| √ | √ | interval | 自动切换时间间隔 | Number | - | 5000 |
| √ | √ | duration | 滑动动画时长 | Number | - | 500 |
| √ | √ | current | 当前所在滑块的 index | Number | - | 0 |
| √ | √ | circular | 是否采用衔接滑动 | Boolean | - | false |
| √ | skipHiddenItemLayout | 是否跳过未显示的滑块布局,设为 true 可优化复杂情况下的滑动性能,但会丢失隐藏状态滑块的布局信息 | Boolean | - | false | |
| √ | displayMultipleItems | 同时显示的滑块数量 | Number | - | 1 | |
| √ | vertical | 滑动方向是否为纵向 | Boolean | - | false | |
| √ | √ | onChange | current 改变时会触发 change 事件 | EventHandle | - | - |
| √ | onAnimationfinish | 动画结束时会触发 animationfinish 事件 | EventHandle | - | - |
Scrollview(滑动图片,文字否)
<View className='at-row'><View className='at-col border'><ScrollView className='scrollview1' scrollX='true'><Image className='large' src='https://img.zcool.cn/community/01005e579e24f10000012e7e903adf.jpg@1280w_1l_0o_100sh.jpg' mode='aspectFit'></Image><Image className='large' src='https://img.zcool.cn/community/0180b1579e251b0000018c1bd2b35f.jpg@1280w_1l_2o_100sh.jpg' mode='aspectFit'></Image><Image className='large' src='https://img.zcool.cn/community/012886579e25000000012e7e270ca6.jpg@1280w_1l_0o_100sh.jpg' mode='aspectFit'></Image></ScrollView></View>
CSS
.border {box-shadow:0 6rpx 6rpx 6rpx lightgray;border-radius:5%;margin-left: 15rpx;margin-right: 15rpx;margin-bottom: 25rpx;}.large {box-shadow:0 3rpx 5rpx 1rpx lightgray;border-radius:5%;width: 60%;height: 240rpx;}
