提交 a84f81bf 编写于 作者: 张磊

更新transition示例使用uni.getElementById操作style

上级 58824d38
...@@ -5,63 +5,33 @@ ...@@ -5,63 +5,33 @@
<view> <view>
<view class="container"> <view class="container">
<text class="text">点击修改宽度</text> <text class="text">点击修改宽度</text>
<view <view class="base-style transition-width" id="widthOrHeight" @click="changeWidthOrHeight"></view>
class="base-style transition-width"
:style="widthOrHeight"
@click="changeWidthOrHeight"
></view>
</view> </view>
<view class="container"> <view class="container">
<text class="text">点击修改Margin</text> <text class="text">点击修改Margin</text>
<view <view class="base-style transition-margin" id="styleMargin" @click="changeMargin"></view>
class="base-style transition-margin"
:style="styleMargin"
@click="changeMargin"
></view>
</view> </view>
<view class="container"> <view class="container">
<text class="text">点击修改Padding</text> <text class="text">点击修改Padding</text>
<view <view class="base-style transition-padding" id="stylePadding" @click="changePadding">
class="base-style transition-padding" <view style="background-color: black; height: 50px; width: 50px"></view>
:style="stylePadding"
@click="changePadding"
>
<view
style="background-color: black; height: 50px; width: 50px"
></view>
</view> </view>
</view> </view>
<view class="container"> <view class="container">
<text class="text">点击修改Background</text> <text class="text">点击修改Background</text>
<view <view class="base-style transition-background" id="styleBackground" @click="changeBackground"></view>
class="base-style transition-background"
:style="styleBackground"
@click="changeBackground"
></view>
</view> </view>
<view class="container"> <view class="container">
<text class="text">点击修改Transform</text> <text class="text">点击修改Transform</text>
<view <view class="base-style transition-transform" id="styleTransform" @click="changeTransform"></view>
class="base-style transition-transform"
:style="styleTransform"
@click="changeTransform"
></view>
</view> </view>
<view class="container"> <view class="container">
<text class="text">点击修改Border</text> <text class="text">点击修改Border</text>
<view <view class="base-style transition-border" id="styleBorder" @click="changeBorder"></view>
class="base-style transition-border"
:style="styleBorder"
@click="changeBorder"
></view>
</view> </view>
<view class="container"> <view class="container">
<text class="text">点击修改Position</text> <text class="text">点击修改Position</text>
<view <view class="base-style transition-position" id="stylePosition" @click="changestylePosition"></view>
class="base-style transition-position"
:style="stylePosition"
@click="changestylePosition"
></view>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
...@@ -70,124 +40,150 @@ ...@@ -70,124 +40,150 @@
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
isTranstionWidthOrHeight: false, isTranstionWidthOrHeight: false,
widthOrHeight: '', widthOrHeight: null as Element | null,
isTranstionChangeMargin: false, isTranstionChangeMargin: false,
styleMargin: '', styleMargin: null as Element | null,
isTransitionStylePadding: false, isTransitionStylePadding: false,
stylePadding: '', stylePadding: null as Element | null,
isTransitionstyleBackground: false, isTransitionstyleBackground: false,
styleBackground: '', styleBackground: null as Element | null,
isTransitionStyleTransform: false, isTransitionStyleTransform: false,
styleTransform: '', styleTransform: null as Element | null,
isTransitionstyleBorder: false, isTransitionstyleBorder: false,
styleBorder: '', styleBorder: null as Element | null,
isTransitionstylePosition: false, isTransitionstylePosition: false,
stylePosition: '', stylePosition: null as Element | null,
} }
}, },
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")
},
methods: { methods: {
changeWidthOrHeight() { changeWidthOrHeight() {
this.widthOrHeight = this.isTranstionWidthOrHeight this.widthOrHeight?.style?.setProperty("width", this.isTranstionWidthOrHeight
? 'width:400rpx' ? '400rpx'
: 'width:600rpx' : '600rpx')
this.isTranstionWidthOrHeight = !this.isTranstionWidthOrHeight this.isTranstionWidthOrHeight = !this.isTranstionWidthOrHeight
}, },
changeMargin() { changeMargin() {
this.styleMargin = this.isTranstionChangeMargin this.styleMargin?.style?.setProperty("margin-top", this.isTranstionChangeMargin
? 'margin-top:0rpx;margin-left:0rpx' ? '0rpx'
: 'margin-top:100rpx;margin-left:100rpx' : '100rpx'
)
this.styleMargin?.style?.setProperty("margin-left", this.isTranstionChangeMargin
? '0rpx'
: '100rpx'
)
this.isTranstionChangeMargin = !this.isTranstionChangeMargin this.isTranstionChangeMargin = !this.isTranstionChangeMargin
}, },
changePadding() { changePadding() {
this.stylePadding = this.isTransitionStylePadding this.stylePadding?.style?.setProperty("padding-top", this.isTransitionStylePadding
? 'padding-top:0rpx;padding-left:0rpx' ? '0rpx'
: 'padding-top:100rpx;padding-left:100rpx' : '100rpx')
this.stylePadding?.style?.setProperty("padding-left", this.isTransitionStylePadding
? '0rpx'
: '100rpx')
this.isTransitionStylePadding = !this.isTransitionStylePadding this.isTransitionStylePadding = !this.isTransitionStylePadding
}, },
changeBackground() { changeBackground() {
this.styleBackground = this.isTransitionstyleBackground this.styleBackground?.style?.setProperty("background-color", this.isTransitionstyleBackground
? 'background-color: brown;opacity:1' ? 'brown'
: 'background-color: black;opacity:0.5' : 'black'
)
this.styleBackground?.style?.setProperty("opacity", this.isTransitionstyleBackground
? '1'
: '0.5'
)
this.isTransitionstyleBackground = !this.isTransitionstyleBackground this.isTransitionstyleBackground = !this.isTransitionstyleBackground
}, },
changeTransform() { changeTransform() {
this.styleTransform = this.isTransitionStyleTransform this.styleTransform?.style?.setProperty("transform", this.isTransitionStyleTransform
? 'transform: rotate(0deg)' ? 'rotate(0deg)'
: 'transform: rotate(135deg)' : 'rotate(135deg)'
)
this.isTransitionStyleTransform = !this.isTransitionStyleTransform this.isTransitionStyleTransform = !this.isTransitionStyleTransform
}, },
changeBorder() { changeBorder() {
this.styleBorder = this.isTransitionstyleBorder this.styleBorder?.style?.setProperty("border-color", this.isTransitionstyleBorder
? 'border-color: brown;' ? 'brown'
: 'border-color: yellow;' : 'yellow'
)
this.isTransitionstyleBorder = !this.isTransitionstyleBorder this.isTransitionstyleBorder = !this.isTransitionstyleBorder
}, },
changestylePosition() { changestylePosition() {
this.stylePosition = this.isTransitionstylePosition this.stylePosition?.style?.setProperty("left", this.isTransitionstylePosition
? 'left:0rpx' ? '0rpx'
: 'left:150rpx;' : '150rpx'
)
this.isTransitionstylePosition = !this.isTransitionstylePosition this.isTransitionstylePosition = !this.isTransitionstylePosition
}, },
}, },
} }
</script> </script>
<style> <style>
.container { .container {
margin: 15rpx; margin: 15rpx;
background-color: white; background-color: white;
} }
.text {
.text {
margin-top: 20rpx; margin-top: 20rpx;
margin-bottom: 32rpx; margin-bottom: 32rpx;
} }
.base-style { .base-style {
width: 400rpx; width: 400rpx;
height: 400rpx; height: 400rpx;
background-color: brown; background-color: brown;
} }
.transition-width { .transition-width {
transition-property: width; transition-property: width;
transition-duration: 1000; transition-duration: 1000;
} }
.transition-margin { .transition-margin {
transition-property: margin-left, margin-top; transition-property: margin-left, margin-top;
transition-duration: 1000; transition-duration: 1000;
} }
.transition-padding { .transition-padding {
transition-property: padding-left, padding-top; transition-property: padding-left, padding-top;
transition-duration: 1000; transition-duration: 1000;
} }
.transition-background { .transition-background {
transition-property: background-color, opacity; transition-property: background-color, opacity;
transition-duration: 1000; transition-duration: 1000;
} }
.transition-transform { .transition-transform {
transition-property: transform; transition-property: transform;
transition-duration: 1000; transition-duration: 1000;
} }
.transition-border { .transition-border {
border-width: 5px; border-width: 5px;
border-color: brown; border-color: brown;
border-style: solid; border-style: solid;
transition-property: border-color; transition-property: border-color;
transition-duration: 1000; transition-duration: 1000;
} }
.transition-position { .transition-position {
transition-property: left; transition-property: left;
transition-duration: 1000; transition-duration: 1000;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册