小程序轮播图

.wxml

<swiper style='height:{{Height}}' indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular='true' previous-margin="0rpx" next-margin="0rpx" indicator-color="#ccc" indicator-active-color="white">

    <block wx:for="{{imgUrls}}" wx:key="index">

      <swiper-item>

        <image src="{{item}}" class="slide-image" bindload='imgheight' style='width:100%' />

      </swiper-item>

    </block>

  </swiper>

.js

data: {

    imgUrls: [

      'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',

      'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',

      'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640'

    ],

    indicatorDots: true,

    autoplay: true,

    interval: 2000,

    duration: 500,

    Height:''

  },


如果我们想设置图片为百分百我们还可以在.js里添加

imgheight(e){

    var winWid = wx.getSystemInfoSync().windowWidth;

    var imgh = e.detail.height;

    var imgw = e.detail.width;

    var swiperH = winWid * imgh / imgw + "px";

    this.setData({

      Height: swiperH

    })

  },

.wxss

想改变指示点位置

.wx-swiper-dots {

    position: relative;

    left: unset !important;

    right: 0;

}

.wx-swiper-dots.wx-swiper-dots-horizontal {

    margin-bottom: -5rpx;

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 微信小程序 swiper组件轮播图 照着开发文档尝试,总是能有所收获.之前做Android开发,做个轮播图并不简单...
    爱斯基摩白阅读 1,607评论 0 0
  • | 微信小程序轮播图实现,实现在首页上轮播图,让效果更好看。查看微信小程序开发文档可知,微信小程序提供swiper...
    guanalex阅读 2,925评论 0 0
  • 微信小程序轮播图实现,比Android 轮播图来说,显得轻松多了。微信小程序提供swiper组件,官网api提供的...
    洪生鹏阅读 10,118评论 4 8
  • 需求 微信swiper组件使用方法完善 回顾 swiper-item 与内部展示的内容的宽度差,形成视觉上的swi...
    广州芦苇科技web前端阅读 1,704评论 0 0
  • 生活中,无论是谁,都有着自己的不容易。想要出类拔萃,必要付出多于他人的努力。没有谁能随随便便成功。基于坚持...
    美月如初阅读 523评论 2 12