transition.uvue 4.3 KB
Newer Older
1 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 70 71 72 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 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 131 132 133 134 135 136 137 138 139 140 141 142
<template>
	<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>
</template>

<script>
	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
			},

			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
			}
		}
	}
</script>

<style>
	.container {
		margin: 15rpx;
		background-color: white;
	}
	.text{
		margin-top: 20rpx;
		margin-bottom: 32rpx;
	}

	.base-style {
		width: 400rpx;
		height: 400rpx;
		background-color: brown;
	}

	.transition-width {
		transition-property: width;
		transition-duration: 1000;
	}

	.transition-margin {
		transition-property: margin-left, margin-top;
		transition-duration: 1000;
	}

	.transition-padding {
		transition-property: padding-left, padding-top;
		transition-duration: 1000;
	}

	.transition-background {
		transition-property: background-color, opacity;
		transition-duration: 1000;
	}

	.transition-transform {
		transition-property: transform;
		transition-duration: 1000;
	}

	.transition-border {
		border-width: 5px;
		border-color: brown;
		transition-property: border-color;
		transition-duration: 1000;
	}

	.transition-position {
		transition-property: left;
		transition-duration: 1000;
	}
</style>