小程序 - 自定义滑动组件

自定义滑动组件

小程序有自己的滑动组件slider,但是外形不够美观,我就在网上找的一个自定义滑动组件,然后在它的基础上做了修改,已经可以很流畅的滑动了:
在这里插入图片描述
这个组件运用了两个自定义的控件,我就一一写出来把
新建一个component文件夹,里面放下这两个文件:
在这里插入图片描述
wxzx-progress中
wxml:

<view class="progress progress__bg" style="width: {
  {orientation == 'landscape' ? width : strokeWidth}}rpx; border-radius:{
  {radius}}rpx; background-color: {
  {backgroundColor}}; height: {
  {orientation == 'landscape' ? strokeWidth : width}}rpx">
  <view class="progress__line" style="width: {
  {orientation == 'landscape' ? percent / 100 * width : strokeWidth}}rpx; height: {
  {orientation == 'landscape' ? strokeWidth : percent / 100 * width}}rpx; top:{
  { portraitOrientation == 'bottom' && orientation == 'portrait' ? (100 - percent) / 100 * width : 0 }}rpx; border-radius:{
  {radius}}rpx; {
  { orientation == 'landscape' ?(activeLineColor[1] ? 'background-image: linear-gradient(to right, ' + activeLineColor[0] + ', ' + activeLineColor[1] + ');' : 'background-color:' + activeColor + ';') : (activeLineColor[1] ? 'background-image: linear-gradient(to top, ' + activeLineColor[0] + ', ' + activeLineColor[1] + ');' : 'background-color:' + activeColor + ';')}}"></view>
</view>

在wxss中:

.progress__bg {
  position: relative;
}

.progress__line {
  position: absolute;
}

在js中:

Component({
  properties: {
    percent: {
      type: [Number, String],
      value: 50
    },
    width: {
      type: [Number, String],
      value: 700
    },
    strokeWidth: {
      type: [Number, String],
      value: 10
    },
    activeColor: {
      type: [String, Array],
      value: '#949494'
    },
    backgroundColor: {
      type: String,
      value: '#e5e5e5'
    },
    radius: {
      type: [Number, String],
      value: 5
    },
    orientation: {
      type: [Number, String],
      value: 'landscape'
      // slider方向 landscape横向 portrait纵向
    },
    portraitOrientation: {
      type: [Number, String],
      value: 'bottom'
      // 纵向方向 top 从上到下 bottom 从下到上
    }
  },
  attached: function () {
    let activeColor = this.data.activeColor;
    if (!!~activeColor.indexOf(',')) {
      this.setData({
        activeLineColor: activeColor.split(',')
      })
    }
  }
})

在json中:

{
“component”: true
}

<
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值