transition.uvue 5.0 KB
Newer Older
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view>
      <view class="container">
        <text class="text">点击修改宽度</text>
        <view
          class="base-style transition-width"
          :style="widthOrHeight"
          @click="changeWidthOrHeight"
        ></view>
      </view>
      <view class="container">
        <text class="text">点击修改Margin</text>
        <view
          class="base-style transition-margin"
          :style="styleMargin"
          @click="changeMargin"
        ></view>
      </view>
      <view class="container">
        <text class="text">点击修改Padding</text>
        <view
          class="base-style transition-padding"
          :style="stylePadding"
          @click="changePadding"
        >
          <view
            style="background-color: black; height: 50px; width: 50px"
          ></view>
        </view>
      </view>
      <view class="container">
        <text class="text">点击修改Background</text>
        <view
          class="base-style transition-background"
          :style="styleBackground"
          @click="changeBackground"
        ></view>
      </view>
      <view class="container">
        <text class="text">点击修改Transform</text>
        <view
          class="base-style transition-transform"
          :style="styleTransform"
          @click="changeTransform"
        ></view>
      </view>
      <view class="container">
        <text class="text">点击修改Border</text>
        <view
          class="base-style transition-border"
          :style="styleBorder"
          @click="changeBorder"
        ></view>
      </view>
      <view class="container">
        <text class="text">点击修改Position</text>
        <view
          class="base-style transition-position"
          :style="stylePosition"
          @click="changestylePosition"
        ></view>
      </view>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
70 71 72
</template>

<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
export default {
  data() {
    return {
      isTranstionWidthOrHeight: false,
      widthOrHeight: '',
      isTranstionChangeMargin: false,
      styleMargin: '',
      isTransitionStylePadding: false,
      stylePadding: '',
      isTransitionstyleBackground: false,
      styleBackground: '',
      isTransitionStyleTransform: false,
      styleTransform: '',
      isTransitionstyleBorder: false,
      styleBorder: '',
      isTransitionstylePosition: false,
      stylePosition: '',
    }
  },
  methods: {
    changeWidthOrHeight() {
      this.widthOrHeight = this.isTranstionWidthOrHeight
        ? 'width:400rpx'
        : 'width:600rpx'
      this.isTranstionWidthOrHeight = !this.isTranstionWidthOrHeight
    },
    changeMargin() {
      this.styleMargin = this.isTranstionChangeMargin
        ? 'margin-top:0rpx;margin-left:0rpx'
        : 'margin-top:100rpx;margin-left:100rpx'
      this.isTranstionChangeMargin = !this.isTranstionChangeMargin
    },
105

DCloud-WZF's avatar
DCloud-WZF 已提交
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 131 132 133 134 135 136 137
    changePadding() {
      this.stylePadding = this.isTransitionStylePadding
        ? 'padding-top:0rpx;padding-left:0rpx'
        : 'padding-top:100rpx;padding-left:100rpx'
      this.isTransitionStylePadding = !this.isTransitionStylePadding
    },
    changeBackground() {
      this.styleBackground = this.isTransitionstyleBackground
        ? 'background-color: brown;opacity:1'
        : 'background-color: black;opacity:0.5'
      this.isTransitionstyleBackground = !this.isTransitionstyleBackground
    },
    changeTransform() {
      this.styleTransform = this.isTransitionStyleTransform
        ? 'transform: rotate(0deg)'
        : 'transform: rotate(135deg)'
      this.isTransitionStyleTransform = !this.isTransitionStyleTransform
    },
    changeBorder() {
      this.styleBorder = this.isTransitionstyleBorder
        ? 'border-color: brown;'
        : 'border-color: yellow;'
      this.isTransitionstyleBorder = !this.isTransitionstyleBorder
    },
    changestylePosition() {
      this.stylePosition = this.isTransitionstylePosition
        ? 'left:0rpx'
        : 'left:150rpx;'
      this.isTransitionstylePosition = !this.isTransitionstylePosition
    },
  },
}
138 139 140
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
141 142 143 144 145 146 147 148
.container {
  margin: 15rpx;
  background-color: white;
}
.text {
  margin-top: 20rpx;
  margin-bottom: 32rpx;
}
149

DCloud-WZF's avatar
DCloud-WZF 已提交
150 151 152 153 154
.base-style {
  width: 400rpx;
  height: 400rpx;
  background-color: brown;
}
155

DCloud-WZF's avatar
DCloud-WZF 已提交
156 157 158 159
.transition-width {
  transition-property: width;
  transition-duration: 1000;
}
160

DCloud-WZF's avatar
DCloud-WZF 已提交
161 162 163 164
.transition-margin {
  transition-property: margin-left, margin-top;
  transition-duration: 1000;
}
165

DCloud-WZF's avatar
DCloud-WZF 已提交
166 167 168 169
.transition-padding {
  transition-property: padding-left, padding-top;
  transition-duration: 1000;
}
170

DCloud-WZF's avatar
DCloud-WZF 已提交
171 172 173 174
.transition-background {
  transition-property: background-color, opacity;
  transition-duration: 1000;
}
175

DCloud-WZF's avatar
DCloud-WZF 已提交
176 177 178 179
.transition-transform {
  transition-property: transform;
  transition-duration: 1000;
}
180

DCloud-WZF's avatar
DCloud-WZF 已提交
181 182 183
.transition-border {
  border-width: 5px;
  border-color: brown;
184
  border-style: solid;
DCloud-WZF's avatar
DCloud-WZF 已提交
185 186 187
  transition-property: border-color;
  transition-duration: 1000;
}
188

DCloud-WZF's avatar
DCloud-WZF 已提交
189 190 191 192 193
.transition-position {
  transition-property: left;
  transition-duration: 1000;
}
</style>