微信小程序仿胖东来轮播和背景效果(有效果图)

效果图

.wxml

复制代码
<view class="swiper-index" style="--width--:{{windowWidth}}px;">
  <image src="{{swiperList[(cardCur + bgIndex == -1?swiperList.length - 1:cardCur + bgIndex > swiperList.length -1?0:cardCur + bgIndex)]}}" class="swiper-bg" style="--filter--:blur({{(1 - radio) * 12}}px);"></image>
  <swiper class="card-swiper square-dot" indicator-dots="true" circular="{{true}}" autoplay="{{true}}" 
  style="--scale--:{{radio}};"
  interval="{{5000}}" duration="500"  indicator-color="#ffffff" indicator-active-color="#F2F2F2"
  bindtransition="cardSition" bindanimationfinish="cardFinish"
  data-windowWidth="{{windowWidth}}" data-bgindex="{{bgIndex}}">
    <swiper-item wx:for="{{swiperList}}" wx:key="index" class="{{cardCur==index?'cur':''}}">
      <view class="swiper-item">
        <image class="swiper-image" src="{{item}}"></image>
      </view>
    </swiper-item>
  </swiper>
</view>
<view style="background: #fff;height: 10px;"></view>

.js

复制代码
Page({
  data: {
    swiperList: [
      'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg',
      'https://ossweb-img.qq.com/images/lol/web201310/skin/big84001.jpg',
      'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
    ],
    cardCur:0,
    windowWidth:wx.getSystemInfoSync().windowWidth,
    radio:1,
    bgIndex:'',
  },
  cardFinish(e){
    this.setData({
      radio:1,
      bgIndex:0,
      cardCur: e.detail.current,
    })
  },
  cardSition(e){
    let dx = Math.abs(e.detail.dx),windowWidth = e.currentTarget.dataset.windowwidth,
    bgindex = e.currentTarget.dataset.bgindex;
    let num = dx / windowWidth
    let radio = 1 - num < 0.9?0.9:1 - num;
    let index = num > 0.45?(e.detail.dx < 0?-1:1):0
    this.setData({
      radio,
    })
    if(index != bgindex){
      this.setData({
        bgIndex:index,
      })
    }
  },
})

.wxss

复制代码
view,scroll-view,swiper,image {box-sizing: border-box;}
.swiper-index{padding: 10px;height: 260px;padding-top:100px;position: relative;}
.swiper-index::after{content: '';width: 120%;position: absolute;
  left: -10%;bottom: -30px;height: 30px;box-shadow: 0 -15px 15px 0px rgba(255,255,255,0.6);}
.swiper-bg{position: absolute;left: 0;top: 0;width: 100%;height: 100%;filter: var(--filter--);z-index: -1;
transition: all 0.3s;}
.card-swiper {height: 130px !important;width: 100%;}
.card-swiper swiper-item {overflow: hidden;border-radius: 20rpx;}
.swiper-image{width:var(--width--);height: 260px;position: absolute;left: -10px;top: -100px;}
.card-swiper swiper-item .swiper-item {width: 100%;display: block;height: 100%;
transition: all 0.2s ease-in 0s;overflow: hidden;}
.card-swiper swiper-item.cur .swiper-item {transform: none;transform: scale(var(--scale--));
transition: all 0.1s ease-in 0s;border-radius: 20rpx;}
swiper.square-dot .wx-swiper-dot {background-color: #fff;opacity: 0.4;width: 10rpx;
height: 10rpx;border-radius: 20rpx;margin: 0 8rpx !important;}
swiper.square-dot .wx-swiper-dot.wx-swiper-dot-active {opacity: 1;width: 30rpx;}

遇到问题可以看我主页加我Q,很少看博客,对你有帮助别忘记点赞收藏。

相关推荐
Dignity_呱2 小时前
如何在不发版时,实现小程序的 AB 测试?
前端·面试·微信小程序
咸虾米_1 天前
微信小程序通过uni.chooseLocation打开地图选择位置,相关设置及可能出现的问题
微信小程序·小程序·uniapp开发·小程序地图api
不如摸鱼去2 天前
Trae 辅助下的 uni-app 跨端小程序工程化开发实践分享
微信小程序·小程序·uni-app·aigc·ai编程
意会2 天前
微信闪照小程序实现
前端·css·微信小程序
小白_ysf2 天前
uniapp 开发微信小程序,获取经纬度并且转化详细地址(单独封装版本)
微信小程序·uni-app
是一碗螺丝粉3 天前
拯救你的app/小程序审核!一套完美避开审核封禁的URL黑名单机制
前端·javascript·微信小程序
我叫黑大帅3 天前
微信小程序分包:告别加载慢,像拆快递一样简单!
前端·微信小程序
两个月菜鸟3 天前
vue+微信小程序 五角星
前端·vue.js·微信小程序
熬耶4 天前
Uniapp之微信小程序自定义底部导航栏形态
微信小程序·小程序·uni-app
誰在花里胡哨5 天前
微信小程序实现陀螺仪卡片景深效果
前端·微信小程序·动效