微信小程序align_微信小程序跃动方块

这是一个关于微信小程序中创建加载动画的示例。通过使用WXML、WXSS和JS文件,实现了五个圆点依次淡入淡出的效果。CSS定义了加载动画的样式,JavaScript部分通过定时器控制动画的循环播放,调整了圆点的不透明度。
摘要由CSDN通过智能技术生成

效果展示

033a8b91b2d39a06f309e3977ab17779.gif

Demo代码

wxml


<view class="loading">
  <view class="dot" animation="{{alpha[0]}}">view>
  <view class="dot" animation="{{alpha[1]}}">view>
  <view class="dot" animation="{{alpha[2]}}">view>
  <view class="dot" animation="{{alpha[3]}}">view>
  <view class="dot" animation="{{alpha[4]}}">view>
view>

wxss

page{
 background-size: cover;
 background-color: black;
}

/** loading.wxss **/
.loading {
 width: 100%;
 position: absolute;
 bottom: 50%;
 justify-content: center;
 text-align: center;
}

.loading .dot{
 background-color:orange;
 display: inline-block;
 /**圆点大小在这里设置,高宽一致,圆角值为高宽的一半**/
 width: 48rpx;
 height: 48rpx;
 border-radius: 8rpx;
 margin: 0 10rpx;
 opacity: 0;
}

js

/* loading.js */
Page({
  data: {
    alpha: [1, 1, 1, 1, 1]
  },
  onLoad: function () {
    var self = this;
    var _index = 0;
    var _alpha = self.data.alpha;
    var _speed = 300;
    var timer = setInterval(function () {
      var an_show = wx.createAnimation({});
      var an_hide = wx.createAnimation({});
      an_show.opacity(1).step({ duration: _speed });
      an_hide.opacity(0).step({ duration: _speed });
      _alpha[_index] = an_show;
      _alpha[_index == 0 ? 4 : _index - 1] = an_hide;
      self.setData({
        alpha: _alpha
      })
      _index = _index == 4 ? 0 : _index + 1;
    }, _speed);
  }
})

效果展示

5b710fa838abaee434bcec3c12ab95f9.gif

Demo代码

wxml


<view class="loading">
  <view class="dot" animation="{{alpha[0]}}">view>
  <view class="dot" animation="{{alpha[1]}}">view>
  <view class="dot" animation="{{alpha[2]}}">view>
  <view class="dot" animation="{{alpha[3]}}">view>
  <view class="dot" animation="{{alpha[4]}}">view>
view>

wxss

page{
 background-size: cover;
 background-color: black;
}

/** loading.wxss **/
.loading {
 width: 100%;
 position: absolute;
 bottom: 50%;
 justify-content: center;
 text-align: center;
}

.loading .dot{
 background-color:white;
 display: inline-block;
 /**圆点大小在这里设置,高宽一致,圆角值为高宽的一半**/
 width: 48rpx;
 height: 48rpx;
 border-radius: 24rpx;
 margin: 0 10rpx;
 opacity: 0;
}

js

/* loading.js */
Page({
  data: {
    alpha: [1, 1, 1, 1, 1]
  },
  onLoad: function () {
    var self = this;
    var _index = 0;
    var _alpha = self.data.alpha;
    var _speed = 300;
    var timer = setInterval(function () {
      var an_show = wx.createAnimation({});
      var an_hide = wx.createAnimation({});
      an_show.opacity(1).step({ duration: _speed });
      an_hide.opacity(0).step({ duration: _speed });
      _alpha[_index] = an_show;
      _alpha[_index == 0 ? 4 : _index - 1] = an_hide;
      self.setData({
        alpha: _alpha
      })
      _index = _index == 4 ? 0 : _index + 1;
    }, _speed);
  }
})

说明

Demo代码已同步至小程序

e9abea94e60464178721edbef956cd2d.gif

写留言|查看留言

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值