小程序自定义轮播图样式

小程序自定义轮播图样式以下是各案例,仅供大家参考。

效果展示:

index.wxml 代码:

复制代码
<view>
 <!-- 轮播 -->
  <view>
    <swiper indicator-dots="{{indicatorDots}}"
          autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="{{circular}}" bindchange="swiperChange">
      <block wx:for="{{banner}}">
        <swiper-item>
          <view>
          <image src="{{item.ad_img}}" mode="scaleToFill"></image>
          <view>
          <view>{{item.ad_name}}</view>
          </view>
          </view>
        </swiper-item>
      </block>
    </swiper>
    <view>
      <block wx:for="{{banner}}" wx:key="unique">
        <view class="dot{{index == swiperCurrent ? ' active' : ''}}"></view>
      </block>
    </view>
  </view>
   <!-- 轮播 -->
</view>

index.js 代码:

复制代码
const app = getApp()
 
Page({
  data: {
    now:'',
    banner: [],
    circular: true,
    indicatorDots: false,
    autoplay: true,
    interval: 4000,
    duration: 800,
    swiperCurrent: 0,
  },
  swiperChange(e) {
    let current = e.detail.current;
    // console.log(current, '轮播图')
    let that = this;
    that.setData({
      swiperCurrent: current,
    })
  },
  //事件处理函数
  bindViewTap: function() {
 
  },
  onLoad: function () {
  this.getBanner(); //获取轮播图
  },
    // 轮播
  getBanner:function(){
    var that=this
    wx.request({
      url: app.AppUrl +'/getBanner',
      success(res) {
        that.setData({
          banner: res.data.res_banner,
        })
      }
    })
  },
})

index.wxss 代码:

复制代码
.lunbo{ width: 96%; margin-left: 2%;  height: 350rpx; background: #000; float: left; border-radius: 15rpx; overflow: hidden;position: relative;}
.lunbo swiper{width: 100%; height: 350rpx; }
.lunbo image{ width: 100%; height: 350rpx; display: block; border-radius: 15rpx;}
.lunbo .name{background: linear-gradient(transparent,rgba(0,0,0,.1) 20%,rgba(0,0,0,.2) 35%,rgba(0,0,0,.3) 65%,rgba(0,0,0,.4));
width: 750rpx;
position: absolute;
bottom: -2rpx;
left: 0px;}
.lunbo .name view{
width: 500rpx;
color: #fff;
padding-left: 20rpx;
padding-bottom: 10rpx;
padding-top: 10rpx;
font-size: 30rpx;
 overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  -webkit-line-clamp: 1;
}
.dots{
  position: absolute;
  right: 0;
  bottom: 20rpx;
  display: flex;
}
.dots .dot{
  margin: 0 8rpx;
  width: 8rpx;
  height: 8rpx;
  background:rgba(255,255,255,0.5);
  border-radius: 8rpx;
  transition: all .6s;
}
.dots .dot.active{
  width: 24rpx;
  background: #fff;
}

小程序自定义轮播图样式-遇见你与你分享

相关推荐
拼图2094 小时前
微信小程序——skyline版本问题
微信小程序·小程序
mg6685 小时前
微信小程序入门实例_____打造你的专属单词速记小程序
微信小程序·小程序
程序员陆通5 小时前
Vibe Coding开发微信小程序实战案例
微信小程序·小程序·notepad++·ai编程
「、皓子~5 小时前
后台管理系统的诞生 - 利用AI 1天完成整个后台管理系统的微服务后端+前端
前端·人工智能·微服务·小程序·go·ai编程·ai写作
nbsaas-boot6 小时前
[特殊字符] 分享裂变新姿势:用 UniApp + Vue3 玩转小程序页面分享跳转!
小程序·uniapp·notepad++
老A技术联盟6 小时前
从小白入门,基于Cursor开发一个前端小程序之Cursor 编程实践与案例分析
前端·小程序
you45806 小时前
小程序学习笔记:使用 MobX 实现全局数据共享,实例创建、计算属性与 Actions 方法
笔记·学习·小程序
风铃喵游6 小时前
构建引擎: 打造小程序编译器
前端·小程序·架构
说私域6 小时前
基于开源AI智能名片链动2+1模式S2B2C商城小程序的抖音渠道力拓展与多渠道利润增长研究
人工智能·小程序·开源
MonkeyKing_sunyuhua7 小时前
微信小程序能不能获取物联网的上的设备数据
物联网·微信小程序·小程序