微信小程序轮播图支持淡入淡出效果吗?
发布于 6 年前 作者 litan 7524 次浏览 来自 问答

问题描述

      微信小程序中的轮播图支持淡入淡出效果。查看swiper组件,并没有提供animation 属性,对轮播动画做处理。

请问小程序支持这样的效果吗?

2 回复

目前不支持animation 属性

只有easing-function 的合法值default,linear,easeInCubic,easeOutCubic,easeInOutCubic

可以自定一个

index.wxml:

<view class="banner">
  <image class="pic" src="../../images/banner1.jpg" animation="{{num==0?showpic:hidepic}}"/>
  <image class="pic" src="../../images/banner2.jpg" animation="{{num==1?showpic:hidepic}}"/>
  <image class="pic" src="../../images/banner3.jpg" animation="{{num==2?showpic:hidepic}}"/></view>

index.wxss:

.banner{    width:750rpx;    height:600rpx;    position: relative;
}.pic{    display:block;    width:750rpx;    height:600rpx;   
    position:absolute; 
    top:0;    left:0;
}

index.js:

Page({  data:{        setTime:'',        num:0,        showpic:null,        hidepic:null,
  },  onLoad:function(){    var _this=this;    var num=_this.data.num;    var animation= wx.createAnimation({}) //创建一个动画实例
    _this.setData({      //创建一个计时器
        setTime:setInterval(function(){
            _this.setData({                num:num++
            })            if(num>2){
              num=0;
            }           //淡入
            animation.opacity(1).step({                  duration:1500
            }) //描述动画
            _this.setData({                showpic:animation.export()
            }) //输出动画
          //淡出
            animation.opacity(0).step({duration:1500})
            _this.setData({hidepic:animation.export()})
      },4000)
    })
  }
})

请问,问题解决了吗?

回到顶部