微信小程序swiper组件切换+个人资料展示

这篇文章的主题就是swiper啦,不过swiper在真机上有个不好的点就是页面切换时会有闪烁回弹的感觉,不知道如何处理,希望有知道如何处理的小伙伴可以给出一些指导意见。那还是先来看看正常的切换吧,这篇主要是为了记录swiper的前后边距的使用。
先看一下常用的一些属性

在这里插入图片描述
这些属性还是比较常用的

看一下演示效果

在这里插入图片描述

  • WXML
<view style="height:{{maxHeight}}px" class='page'>
<!-- 参数详见 https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html -->
  <swiper class='swiperClass' indicator-color="#a39f99" indicator-active-color="#f49641" 
indicator-dots interval="2000" duration="1000" previous-margin="{{margin}}px" 
next-margin="{{margin}}px" circular bindchange="bindchange" display-multiple-items="1"
    style="height:{{maxHeight}}px">
    <block wx:for="{{list}}" wx:key="{{index}}">
      <swiper-item>
        <view style='width:{{swiperItemWidth}}px;height:{{swiperItemHeigth}}px' 
class="user {{swiperIndex == index ? 'active' : 'quiet'}}">
          <view class='top'>
            <view class='person_info'>
              <image class='user_avatar' src="{{item.img}}"></image>
              <view class='user_name'>{{item.name}}</view>
            </view>
          </view>
          <view>
            <view class="one-line">出生年月 : {{item.birth}}</view>
            <view class="one-line">性别 : {{item.sex}}</view>
            <view class="one-line">毕业院校 : {{item.graduate}}</view>
            <view class="one-line">专业 : {{item.professional}}</view>
            <view class="one-line">毕业时间 : {{item.graduateTime}}</view>
             <view class="one-line">籍贯 : {{item.nativePlace}}</view>
             <view class="one-line">邮箱 : {{item.email}}</view>
          </view>
        </view>
      </swiper-item>
    </block>
  </swiper>
</view>
  • WXSS
page {
  height: 100%;
  background: #f3f3f3;
  position: relative;
}
.entire-module {
  width: 100%;
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
.swiperClass {
  margin: 0;
}
.user {
  position: relative;
  background: #f9f9f9;
  z-index: -2;
}
.active {
  transform: none;
  transition: all 0.2s ease-in 0s;
}
.quiet {
  transform: scale(0.9);
  transition: all 0.2s ease-in 0s;
}
.top {
  position: relative;
  width: 100%;
  height: 198rpx;
  background:#B0C4DE;
}
.user_avatar {
  width: 120rpx;
  height: 120rpx;
  background: rgb(226, 222, 222);
  margin-right: 20rpx;
}
.person_info {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0 40rpx;
}
.person_info>view {
  flex: 1;
  height: 120rpx;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 30rpx;
}
.one-line{
  font-size: 30rpx;
  margin-top: 2.6vh;
  padding-left: 3vw;
  /* padding: 1vh 3vw; */
}
  • JS
Page({
  data: {
    list: [{
        img: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562746384&di=79b1c4202963a9b02db57e30d8986824&imgtype=jpg&er=1&src=http%3A%2F%2Fgss0.baidu.com%2F-4o3dSag_xI4khGko9WTAnF6hhy%2Fbainuo%2Fcrop%3D0%2C0%2C1130%2C1225%3Bw%3D640%3Bq%3D84%2Fsign%3D9858a73cdd09b3defff0be28f18f40b1%2F8718367adab44aede065beb0bf1c8701a18bfbbf.jpg",
        name: "张舒雅",
        birth: "1996年5月12日",
        sex:'女',
        graduate:"华东师范大学",
        professional:"软件工程",
        graduateTime:"2018年6月30日",
        nativePlace:"广东省广州市",
        email:"1174569803@qq.com" 
      },
      {
        img: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562746427&di=d5f55b69d6fa62495fdd3b53d3efe56e&imgtype=jpg&er=1&src=http%3A%2F%2Fci.xiaohongshu.com%2Ff8098da8-b162-4b96-ba5a-86135475ca81%40r_750w_750h_ss1.jpg',
        name: "李思琦",
        birth: "1994年10月26日",
        sex: '女',
        graduate:"南京财经大学",
        professional: "计算机科学与技术",
        graduateTime: "2016年6月30日",
        nativePlace: "河南省安阳市",
        email: "2648569803@qq.com" 
      },
      {
        img: 'http://imgsrc.baidu.com/forum/w=580/sign=1598364951ee3d6d22c687c373176d41/1e4ebe096b63f6242fc51ced8f44ebf81b4ca311.jpg',
        name: "刘栋",
        sex: '男',
        birth: "1993年4月29日",
        graduate:"哈尔滨工业大学",
         professional: " 数字媒体技术",
        graduateTime: "2015年6月30日",
        nativePlace: "黑龙江哈尔滨市",
        email: "1462751065@qq.com" 
      }

    ],
    swiperIndex: 0, //这里不写第一次启动展示的时候会有问题
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        console.log(res);
        var swiperItemWidth = parseInt(res.windowWidth * 6 / 7);
        console.log(swiperItemWidth)
        var swiperItemHeigth = parseInt(swiperItemWidth / 2 * 3);
        var margin = parseInt((res.windowWidth - swiperItemWidth) / 2);
        that.setData({
          margin: margin,
          swiperItemHeigth: swiperItemHeigth,
          swiperItemWidth: swiperItemWidth,
          maxHeight: parseInt(swiperItemWidth / 0.62)
        })
        console.log('打印最大高度', that.data.maxHeight)
      },
    })
  },
  //轮播切换
  bindchange(e) {
    this.setData({
      swiperIndex: e.detail.current
    })
  },
})```

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值