transition.uvue 5.9 KB
Newer Older
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
4
  <!-- #endif -->
DCloud-WZF's avatar
DCloud-WZF 已提交
5 6 7
    <view>
      <view class="container">
        <text class="text">点击修改宽度</text>
8
        <view class="base-style transition-width" id="widthOrHeight" @click="changeWidthOrHeight"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
9 10 11
      </view>
      <view class="container">
        <text class="text">点击修改Margin</text>
12
        <view class="base-style transition-margin" id="styleMargin" @click="changeMargin"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
13 14 15
      </view>
      <view class="container">
        <text class="text">点击修改Padding</text>
16 17
        <view class="base-style transition-padding" id="stylePadding" @click="changePadding">
          <view style="background-color: black; height: 50px; width: 50px"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19 20 21
        </view>
      </view>
      <view class="container">
        <text class="text">点击修改Background</text>
22
        <view class="base-style transition-background" id="styleBackground" @click="changeBackground"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25
      </view>
      <view class="container">
        <text class="text">点击修改Transform</text>
26
        <view class="base-style transition-transform" id="styleTransform" @click="changeTransform"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
27 28 29
      </view>
      <view class="container">
        <text class="text">点击修改Border</text>
30
        <view class="base-style transition-border" id="styleBorder" @click="changeBorder"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
31 32 33
      </view>
      <view class="container">
        <text class="text">点击修改Position</text>
34
        <view class="base-style transition-position" id="stylePosition" @click="changestylePosition"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
35 36
      </view>
    </view>
37
  <!-- #ifdef APP -->
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39
  </scroll-view>
  <!-- #endif -->
40 41 42
</template>

<script>
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  export default {
    data() {
      return {
        isTranstionWidthOrHeight: false,
        widthOrHeight: null as Element | null,
        isTranstionChangeMargin: false,
        styleMargin: null as Element | null,
        isTransitionStylePadding: false,
        stylePadding: null as Element | null,
        isTransitionstyleBackground: false,
        styleBackground: null as Element | null,
        isTransitionStyleTransform: false,
        styleTransform: null as Element | null,
        isTransitionstyleBorder: false,
        styleBorder: null as Element | null,
        isTransitionstylePosition: false,
        stylePosition: null as Element | null,
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
61
    },
62 63 64 65 66 67 68 69
    onReady() {
      this.widthOrHeight = uni.getElementById("widthOrHeight")
      this.styleMargin = uni.getElementById("styleMargin")
      this.stylePadding = uni.getElementById("stylePadding")
      this.styleBackground = uni.getElementById("styleBackground")
      this.styleTransform = uni.getElementById("styleTransform")
      this.styleBorder = uni.getElementById("styleBorder")
      this.stylePosition = uni.getElementById("stylePosition")
DCloud-WZF's avatar
DCloud-WZF 已提交
70
    },
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    methods: {
      changeWidthOrHeight() {
        this.widthOrHeight?.style?.setProperty("width", this.isTranstionWidthOrHeight
          ? '400rpx'
          : '600rpx')
        this.isTranstionWidthOrHeight = !this.isTranstionWidthOrHeight
      },
      changeMargin() {
        this.styleMargin?.style?.setProperty("margin-top", this.isTranstionChangeMargin
          ? '0rpx'
          : '100rpx'
        )
        this.styleMargin?.style?.setProperty("margin-left", this.isTranstionChangeMargin
          ? '0rpx'
          : '100rpx'
        )
        this.isTranstionChangeMargin = !this.isTranstionChangeMargin
      },
89

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
      changePadding() {
        this.stylePadding?.style?.setProperty("padding-top", this.isTransitionStylePadding
          ? '0rpx'
          : '100rpx')
        this.stylePadding?.style?.setProperty("padding-left", this.isTransitionStylePadding
          ? '0rpx'
          : '100rpx')
        this.isTransitionStylePadding = !this.isTransitionStylePadding
      },
      changeBackground() {
        this.styleBackground?.style?.setProperty("background-color", this.isTransitionstyleBackground
          ? 'brown'
          : 'black'
        )
        this.styleBackground?.style?.setProperty("opacity", this.isTransitionstyleBackground
          ? '1'
          : '0.5'
        )
        this.isTransitionstyleBackground = !this.isTransitionstyleBackground
      },
      changeTransform() {
        this.styleTransform?.style?.setProperty("transform", this.isTransitionStyleTransform
          ? 'rotate(0deg)'
          : 'rotate(135deg)'
        )
        this.isTransitionStyleTransform = !this.isTransitionStyleTransform
      },
      changeBorder() {
        this.styleBorder?.style?.setProperty("border-color", this.isTransitionstyleBorder
          ? 'brown'
          : 'yellow'
        )
        this.isTransitionstyleBorder = !this.isTransitionstyleBorder
      },
      changestylePosition() {
        this.stylePosition?.style?.setProperty("left", this.isTransitionstylePosition
          ? '0rpx'
          : '150rpx'
        )
        this.isTransitionstylePosition = !this.isTransitionstylePosition
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
131
    },
132
  }
133 134 135
</script>

<style>
136 137 138 139 140 141 142 143 144
  .container {
    margin: 15rpx;
    background-color: white;
  }

  .text {
    margin-top: 20rpx;
    margin-bottom: 32rpx;
  }
145

146 147 148 149 150
  .base-style {
    width: 400rpx;
    height: 400rpx;
    background-color: brown;
  }
151

152 153 154 155
  .transition-width {
    transition-property: width;
    transition-duration: 1000;
  }
156

157 158 159 160
  .transition-margin {
    transition-property: margin-left, margin-top;
    transition-duration: 1000;
  }
161

162 163 164 165
  .transition-padding {
    transition-property: padding-left, padding-top;
    transition-duration: 1000;
  }
166

167 168 169 170
  .transition-background {
    transition-property: background-color, opacity;
    transition-duration: 1000;
  }
171

172 173 174 175
  .transition-transform {
    transition-property: transform;
    transition-duration: 1000;
  }
176

177 178 179 180 181 182 183
  .transition-border {
    border-width: 5px;
    border-color: brown;
    border-style: solid;
    transition-property: border-color;
    transition-duration: 1000;
  }
184

185 186 187 188 189
  .transition-position {
    transition-property: left;
    transition-duration: 1000;
  }
</style>