zoukankan      html  css  js  c++  java
  • 百度小程序-swiper组件

    .swan

            <!-- 轮播图S -->
            <view class="swiper-box">
                <swiper class="banner" style='height:{{swiperH}}' bindchange="swiperChange" autoplay="true" interval="3000" duration="500"
                 circular="true">
                    <block s-for="banner" s-for-index="index" s-for-item="item">
                        <swiper-item>
                            <image src="{{item.cover_id}}" class="slide-image" mode="widthFix" bindload='imgHeight' />
                        </swiper-item>
                    </block>
                </swiper>
                <view class="dots">
                    <block s-for="banner" s-for-index="index" s-for-item="item">
                        <view class="dot {{index == swiperCurrent  ? 'active' : ''}}"></view>
                    </block>
                </view>
            </view>
            <!-- 轮播图E -->

    .css

    /* 轮播图 S*/
    .slide-image{width: 100%;}
    /* 圆点样式控制 S*/
    .swiper-box{position: relative; width: 100%;}
    .dots{position: absolute; left: 0; right: 0; bottom: 0; display: -webkit-box; display: -webkit-flex; display: -moz-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -webkit-justify-content: center; -moz-box-pack: center; -ms-flex-pack: center; justify-content: center; padding: 10rpx 0; background: rgba(0, 0, 0, .2)}
    .dots .dot{margin: 0 8rpx; width: 14rpx; height: 14rpx; background: rgba(255,255,255,.8); border-radius: 8rpx; -webkit-transition: all .6s; transition: all .6s;}
    .dots .dot.active{width: 40rpx; background: #ef782c;}
    /* 圆点样式控制 E*/
    /* 轮播图 E*/

    .js

     1 const app = getApp();
     2 Page({
     3     data: {
     4         banner: [],//轮播图
     5         swiperCurrent: "",//轮播图圆点
     6         swiperH: "",  //这是swiper框要动态设置的高度属性
     7     },
     8     onLoad: function () {
     9         // 监听页面加载的生命周期函数
    10         this.getBanner();
    11     },
    12     onReady: function() {
    13         // 监听页面初次渲染完成的生命周期函数
    14     },
    15     onShow: function() {
    16         // 监听页面显示的生命周期函数
    17         app.setInfo();
    18     },
    19     onHide: function() {
    20         // 监听页面隐藏的生命周期函数
    21     },
    22     onUnload: function() {
    23         // 监听页面卸载的生命周期函数
    24     },
    25     onPullDownRefresh: function() {
    26         // 监听用户下拉动作
    27     },
    28     onReachBottom: function() {
    29         // 页面上拉触底事件的处理函数
    30     },
    31     onShareAppMessage: function () {
    32         // 用户点击右上角转发
    33     },
    34     swiperChange: function (e) {
    35         this.setData({
    36             swiperCurrent: e.detail.current   //获取当前轮播图片的下标
    37         })
    38     },
    39     imgHeight: function (e) {
    40         var winWid = swan.getSystemInfoSync().screenWidth;
    41         var imgh = e.detail.height;//图片高度
    42         var imgw = e.detail.width;//图片宽度
    43         var swiperH = winWid * imgh / imgw + "px";
    44         //等比设置swiper的高度。 即 屏幕宽度 / swiper高度 = 图片宽度 / 图片高度  ==》swiper高度 = 屏幕宽度 * 图片高度 / 图片宽度
    45         this.setData({
    46             swiperH: swiperH//设置高度
    47         });
    48     },
    49     getBanner: function () {//获取banner轮播图
    50         var that = this;
    51         swan.request({
    52             url: app.globalData.baseUrl + 'list/banner',
    53             method: 'GET',
    54             header: {
    55                 genToken: app.globalData.genToken,
    56             },
    57             success: function (res) {
    58                 // console.log(res);
    59                 that.setData({
    60                     banner: res.data.lines
    61                 })
    62                 // console.log(that.data.banner)
    63             }
    64         });
    65     }
    66 });

     效果图

  • 相关阅读:
    我爬取了爬虫岗位薪资,分析后发现爬虫真香
    红薯,撑起父亲的快乐,让我揪心
    跨域问题服务端解决办法 Request header field Authorization is not allowed by Access-Control-Allow-Headers
    antdvue2.x 使用阿里iconfont自定义组件iconfont
    前端 crypto-js aes 加解密
    jsencrypt加密解密字符串
    CryptoJS base64使用方法
    客户端js生成rsa 密钥对
    js动态添加style样式
    PHP 使用非对称加密算法(RSA)
  • 原文地址:https://www.cnblogs.com/suni1024/p/11008485.html
Copyright © 2011-2022 走看看