Animation.translateZ

解释: 对 Z 轴平移

方法参数

Number tz

参数说明

在 Z 轴偏移 tz ,单位 px。

示例

在开发者工具中预览效果

图片示例

Animation.translateZ - 图1

Animation.translateZ - 图2

Animation.translateZ - 图3

代码示例

  1. <view class="wrap">
  2. <view class="animation-element-wrapper">
  3. <view class="animation-element" animation="{{animation}}"></view>
  4. </view>
  5. <view class="card-area">
  6. <view class="top-description border-bottom">展示动画</view>
  7. <button type="primary" bindtap="translateZ">translateZ</button>
  8. </view>
  9. </view>
  1. Page({
  2. data:{ },
  3. onReady() {
  4. this.animation = swan.createAnimation({
  5. transformOrigin: "50% 50%",
  6. duration: 1000,
  7. timingFunction: "ease",
  8. delay: 0
  9. })
  10. },
  11. translateZ() {
  12. let distance = (Math.random() * 2).toFixed(2)
  13. this.animation.translateZ(distance).step()
  14. this.setData({animation: this.animation.export()})
  15. swan.showToast({
  16. title: 'z轴的平移距离为' + distance,
  17. icon: 'none'
  18. });
  19. }
  20. });