Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
a17f3bc7
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6007
Star
91
Fork
164
代码
文件
提交
分支
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看板
提交
a17f3bc7
编写于
8月 17, 2023
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化 示例drop-card 通过dom的ref操作减少diff、过度动画替代帧动画
上级
7a2ad376
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
139 addition
and
100 deletion
+139
-100
pages/template/drop-card/drop-card.uvue
pages/template/drop-card/drop-card.uvue
+139
-100
未找到文件。
pages/template/drop-card/drop-card.uvue
浏览文件 @
a17f3bc7
<template>
<template>
<view class="root">
<view class="root">
<view class="card"
<template v-for="(item,index) in cardList" :key="index">
:style="{'top':Math.abs(x)/-60 + 90 +'px',transform:'scale('+(movePercent/10+0.80)+')','height':cardHeight+'px'}">
<view class="card" ref="card" @touchstart="touchstart($event as TouchEvent,index)" @touchmove="touchmove($event as TouchEvent,index)" @touchend="touchend" @touchcancel="touchend">
<image class="user-img" :src="userList[0]" :style="{'height':cardHeight+'px'}"></image>
<image class="card-img" ref="card-img" :src="item"></image>
</view>
<template v-if="index == 2">
<view class="card"
:style="{'top':Math.abs(x)/-30 + 45 +'px',transform:'scale('+(movePercent/10+0.90)+')','height':cardHeight+'px'}">
<image class="user-img" :src="userList[1]" :style="{'height':cardHeight+'px'}"></image>
</view>
<view @touchmove="touchmove" @touchstart="touchstart" @touchend="touchend"
:style="{'transform':'translate('+x+'px,'+y+'px) rotate('+x/-30+'deg)','height':cardHeight+'px'}" class="card">
<image class="user-img" :src="userList[2]" :style="{'height':cardHeight+'px'}"></image>
<view class="state">
<view class="state">
<image class="state-icon like" :style="{'opacity':x < 0 ? 0 : movePercent * 10}" src="/static/template/drop-card/like.png" mode="widthFix"></image>
<image class="state-icon like" ref="state-icon-like" src="/static/template/drop-card/like.png" mode="widthFix"></image>
<image class="state-icon dislike" :style="{'opacity':x > 0 ? 0 : movePercent * 10}" src="/static/template/drop-card/dislike.png" mode="widthFix"></image>
<image class="state-icon dislike" ref="state-icon-dislike" src="/static/template/drop-card/dislike.png" mode="widthFix"></image>
</view>
</view>
</template>
</view>
</view>
</template>
</view>
</view>
</template>
</template>
<script lang="ts">
<script lang="ts">
let sX : number = 0,
let sX : number = 0,
sY : number = 0,
sY : number = 0,
screenWidth : number = 1;
screenWidth : number = 1,
nodesMap = new Map<string, INode[]>();
export default {
export default {
data() {
data() {
return {
return {
x: 0,
x: 0,
y: 0,
y: 0,
cardHeight:1,
cardList: [
userList: [
'/static/template/drop-card/1.jpg',
'/static/template/drop-card/1.png',
'/static/template/drop-card/2.jpg',
'/static/template/drop-card/2.png',
'/static/template/drop-card/3.jpg'
'/static/template/drop-card/3.png'
] as string[],
]
NodesMap: new Map<string, INode[]>(),
}
},
onReady() {
this.setStyle('card',2,'transitionTimingFunction','ease-in-out');
this.setStyle('card',2,'transitionProperty','transform');
uni.getSystemInfo({
success: (e) => {
// console.log('e',e);
screenWidth = e.screenWidth;
let height = e.screenHeight - 200 + 'px'
for (var i = 0; i < 3; i++) {
this.setStyle('card',i,'height', height);
this.setStyle('card-img',i,'height', height);
}
}
})
},
watch: {
x() {
this.onMove()
},
y() {
this.onMove()
}
}
},
},
computed: {
computed: {
movePercent() : number {
movePercent() : number {
return Math.abs(this.x) /
screenWidth
return Math.abs(this.x) /
(screenWidth/2*3)
},
},
likeOpacity() : number
{
likeOpacity() : number
{
return this.x < 0 ? 0 : this.movePercent * 100
return this.x < 0 ? 0 : this.movePercent * 100
},
},
dislikeOpacity() : number
{
dislikeOpacity() : number
{
return this.x > 0 ? 0 : this.movePercent * 100
return this.x > 0 ? 0 : this.movePercent * 100
}
}
},
},
onLoad() {
methods: {
uni.getSystemInfo({
setStyle(refName:string,index:number,propertyName:string,propertyStyle:any):void{
success: (e) => {
let nodes:INode[]|null = nodesMap.get(refName)
console.log('e',e);
if(nodes == null){
screenWidth = e.screenWidth
nodes = this.$refs.get(refName) as INode[]
this.cardHeight = e.screenHeight - 200
nodesMap.set(refName,nodes)
}else{
// console.log('直接拿');
}
}
})
(nodes)[index].style.setProperty(propertyName,propertyStyle);
},
},
methods: {
onMove() {
changeUserList() {
this.setStyle('card',0,'transform', 'scale('+(this.movePercent/10+0.80)+')')
let user:string = this.userList[this.userList.length - 1]
this.setStyle('card',1,'transform', 'scale('+(this.movePercent/10+0.90)+')')
this.userList.unshift(user)
this.setStyle('card',2,'transform', 'translateX('+this.x+'px) translateY('+this.y+'px) rotate('+this.x/-30+'deg)')
this.userList.pop()
this.x = 0;
this.setStyle('state-icon-like',0,'opacity', x < 0 ? 0 : movePercent * 10)
this.y = 0;
this.setStyle('state-icon-dislike',0,'opacity', x > 0 ? 0 : movePercent * 10)
},
changeCardList() {
let newArr = this.cardList.slice();
this.cardList[0] = newArr[2]
this.cardList[1] = newArr[0]
this.cardList[2] = newArr[1]
this.x = 0
this.y = 0
},
},
touchstart(e : TouchEvent) {
touchstart(e : TouchEvent,index:number) {
if(index != 2){
return
}
sX = e.touches[0].screenX;
sX = e.touches[0].screenX;
sY = e.touches[0].screenY;
sY = e.touches[0].screenY;
},
},
touchmove(e : TouchEvent) {
touchmove(e : TouchEvent,index:number) {
if(index != 2){
return
}
this.x += e.touches[0].screenX - sX;
this.x += e.touches[0].screenX - sX;
this.y += e.touches[0].screenY - sY;
this.y += e.touches[0].screenY - sY;
sX = e.touches[0].screenX;
sX = e.touches[0].screenX;
sY = e.touches[0].screenY;
sY = e.touches[0].screenY;
},
},
touchend() {
touchend() {
if (this.x > screenWidth / 6) {
// console.log('touchend');
let interval : number = 0;
interval = setInterval(() => {
// 设置释放之后飘走的方向 0回到坐标中心 1向右 2向左
this.x += 10
let k:number = 0;
this.y += 3
if (this.x > screenWidth / 6 ) {
if (this.x > screenWidth) {
k = 1
clearInterval(interval)
}else if(this.x < screenWidth * -1 / 6){
this.changeUserList()
k = -1
}
}, 6)
} else if (this.x < screenWidth * -1 / 6) {
let interval : number = 0;
interval = setInterval(() => {
this.x -= 10
this.y += 3
if (this.x < -screenWidth) {
clearInterval(interval)
this.changeUserList()
}
}, 6)
} else {
this.x = 0
this.y = 0
}
}
// 设置动画时间
let time = 400;
this.setStyle('card',2,'transitionDuration',time.toFixed(0));
this.x = screenWidth * 1.5 * k
this.y = Math.abs(screenWidth * 0.5 * k)
setTimeout(()=>{
//关闭动画
this.setStyle('card',2,'transitionDuration',0);
// 更改卡片上的图片内容
if(k != 0){
this.changeCardList()
}
},time)
}
}
}
}
}
}
...
@@ -117,9 +153,10 @@
...
@@ -117,9 +153,10 @@
border-radius: 10px;
border-radius: 10px;
color: #FFF;
color: #FFF;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
z-index: 100;
}
}
.
user-img{
.
card-img {
border-radius: 10px;
border-radius: 10px;
}
}
...
@@ -132,6 +169,7 @@
...
@@ -132,6 +169,7 @@
flex-direction: row;
flex-direction: row;
justify-content: space-between;
justify-content: space-between;
}
}
.state-icon {
.state-icon {
width: 30px;
width: 30px;
height: 30px;
height: 30px;
...
@@ -140,5 +178,6 @@
...
@@ -140,5 +178,6 @@
padding: 3px;
padding: 3px;
border-radius: 100px;
border-radius: 100px;
box-shadow: 0 0 1px #EBEBEB;
box-shadow: 0 0 1px #EBEBEB;
opacity: 0;
}
}
</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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录