• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

百度小程序-swiper组件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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

 效果图


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
我的第一个vb实例--红楼梦测试小程序发布时间:2022-07-18
下一篇:
微信小程序---事件绑定发布时间:2022-07-18
热门推荐
    热门话题
    阅读排行榜

    扫描微信二维码

    查看手机版网站

    随时了解更新最新资讯

    139-2527-9053

    在线客服(服务时间 9:00~18:00)

    在线QQ客服
    地址:深圳市南山区西丽大学城创智工业园
    电邮:jeky_zhao#qq.com
    移动电话:139-2527-9053

    Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap