小程序自定义轮播图样式

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

效果展示:

3.gif

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;
}

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

相关推荐

  1. 微信程序九宫格布局,

    2023-12-19 05:32:03       64 阅读
  2. 微信程序实现

    2023-12-19 05:32:03       37 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-19 05:32:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-19 05:32:03       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-19 05:32:03       82 阅读
  4. Python语言-面向对象

    2023-12-19 05:32:03       91 阅读

热门阅读

  1. 前端技术的新趋势:React、Vue与Angular的比较

    2023-12-19 05:32:03       62 阅读
  2. Cmake基础(5)

    2023-12-19 05:32:03       68 阅读
  3. CSS新手入门笔记整理:CSS3文本样式

    2023-12-19 05:32:03       51 阅读
  4. nginx部署vue项目

    2023-12-19 05:32:03       46 阅读
  5. 【云原生】华为云踩坑日志(更新于2023.12.10)

    2023-12-19 05:32:03       60 阅读
  6. 重构第六章:重构API

    2023-12-19 05:32:03       60 阅读
  7. MySQL5.7忘记root密码

    2023-12-19 05:32:03       61 阅读
  8. kafka安装配置

    2023-12-19 05:32:03       62 阅读
  9. 实现前端指纹登录的简单示例

    2023-12-19 05:32:03       55 阅读