Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
a84f81bf
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5992
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
a84f81bf
编写于
9月 26, 2023
作者:
张
张磊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新transition示例使用uni.getElementById操作style
上级
58824d38
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
142 addition
and
146 deletion
+142
-146
pages/CSS/transition/transition.uvue
pages/CSS/transition/transition.uvue
+142
-146
未找到文件。
pages/CSS/transition/transition.uvue
浏览文件 @
a84f81bf
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<!-- #endif -->
<view>
<view class="container">
<text class="text">点击修改宽度</text>
<view
class="base-style transition-width"
:style="widthOrHeight"
@click="changeWidthOrHeight"
></view>
<view class="base-style transition-width" id="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 class="base-style transition-margin" id="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 class="base-style transition-padding" id="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 class="base-style transition-background" id="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 class="base-style transition-transform" id="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 class="base-style transition-border" id="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 class="base-style transition-position" id="stylePosition" @click="changestylePosition"></view>
</view>
</view>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</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
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,
}
},
changeMargin() {
this.styleMargin = this.isTranstionChangeMargin
? 'margin-top:0rpx;margin-left:0rpx'
: 'margin-top:100rpx;margin-left:100rpx'
this.isTranstionChangeMargin = !this.isTranstionChangeMargin
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: {
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
},
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
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
},
},
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;
}
.container {
margin: 15rpx;
background-color: white;
}
.text {
margin-top: 20rpx;
margin-bottom: 32rpx;
}
.base-style {
width: 400rpx;
height: 400rpx;
background-color: brown;
}
.base-style {
width: 400rpx;
height: 400rpx;
background-color: brown;
}
.transition-width {
transition-property: width;
transition-duration: 1000;
}
.transition-width {
transition-property: width;
transition-duration: 1000;
}
.transition-margin {
transition-property: margin-left, margin-top;
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-padding {
transition-property: padding-left, padding-top;
transition-duration: 1000;
}
.transition-background {
transition-property: background-color, opacity;
transition-duration: 1000;
}
.transition-background {
transition-property: background-color, opacity;
transition-duration: 1000;
}
.transition-transform {
transition-property: transform;
transition-duration: 1000;
}
.transition-transform {
transition-property: transform;
transition-duration: 1000;
}
.transition-border {
border-width: 5px;
border-color: brown;
border-style: solid;
transition-property: border-color;
transition-duration: 1000;
}
.transition-border {
border-width: 5px;
border-color: brown;
border-style: solid;
transition-property: border-color;
transition-duration: 1000;
}
.transition-position {
transition-property: left;
transition-duration: 1000;
}
</style>
.transition-position {
transition-property: left;
transition-duration: 1000;
}
</style>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录