uniapp项目轮播图怎么删除默认样式,改为自定义的样式

在项目中,为了给用户更好的视觉体验,有时我们需要将uniapp官网中提供的轮播图swiper组件自带的样式,改为自定义的样式。

1、将组件中自带的属性indicator-dots(是否显示面板指示点去掉

2、需要写一个大盒子将swiper和view(放指示点)包住。定位:父相子绝,让指示点居中

3、给轮播图一个改变事件chang(),图片变化时 指示点颜色改变

<!-- 轮播图 -->
    <view class="" style="position: relative;">
      <swiper :autoplay="true" circular :interval="3000" :duration="1000" class="swiper_wrapper autoMargin"
        @change="change">
        <swiper-item>
          <view class="swiper-itemsa">
            <image
              src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F0174d95da92543a8012163ba2b098e.jpg%401280w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1668068380&t=ab7379ecd7efda7f2aa0d03e55fff646"
              mode=""></image>
          </view>
        </swiper-item>
        <swiper-item>
          <view class="swiper-itemsa">
            <image
              src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01a23c61529c6011013e89433f2fa4.jpg%401280w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1668068380&t=4d344a0c181b0f75c2619e6e438ccae8"
              mode=""></image>
          </view>
        </swiper-item>
        <swiper-item>
          <view class="swiper-itemsa">
            <image
              src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F016a515da9255ea8012163ba78221c.jpg%401280w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1668068380&t=eb616536ddb75d8582e52c47954683ac"
              mode=""></image>
          </view>
        </swiper-item>
      </swiper>
      <view class=""
        style="display: flex;position: absolute;bottom: 20rpx;left: 50%;transform: translateX(-50%);">
        <view v-for="(i,index)  in data.length" :class="index== swIndex?'sw-ac':'sw'"></view>
      </view>
    </view>

css文件

.scroll-img-one {
    width: 108rpx;
    height: 78rpx;
  }

  .sw {
    width: 32rpx;
    height: 4rpx;
    background-color: #000000;
    margin: 0 12rpx;
  }

  .sw-ac {
    width: 32rpx;
    height: 4rpx;
    background-color: #0BCE56;
    margin: 0 12rpx;
  }
// 轮播图
  .swiper_wrapper {
    transform: translateY(0);
    overflow: hidden;
    border-radius: 16rpx 16rpx 16rpx 16rpx !important;
  }

  .swiper-itemsa {
    width: 100%;
    height: 332rpx;

    image {
      width: 100%;
      height: 100%;
      // border-radius: 16rpx 16rpx 16rpx 16rpx;
    }
  }

  .swiper_wrapper .wx-swiper-dot {
    width: 32rpx;
    height: 4rpx;
    background: #000000;
  }

  .swiper_wrapper .wx-swiper-dot.wx-swiper-dot-active {
    width: 32rpx;
    height: 4rpx;
    background: #0BCE56;
  }

  // 滚动图
  .scroll-box {
    margin-left: 24rpx;
  }

  .scroll-view_H {
    margin-top: 10px;
    white-space: nowrap;
    // width: 100%;

  }

  .scroll-view-item_H {
    display: inline-block;

    &:last-child .box {
      margin-right: 24rpx;
    }
  }
 data() {
      return {
        swIndex: 0,
        data: [{

          },
          {

          }, {

          }
        ]
      }
    },
    methods: {
      change({
        detail
      }) {
        this.swIndex = detail.current
      }
    }
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值