Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
b0d348fd
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6005
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看板
提交
b0d348fd
编写于
8月 09, 2023
作者:
DCloud-yyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加半屏弹窗示例
上级
0a34e41c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
199 addition
and
1 deletion
+199
-1
pages.json
pages.json
+10
-1
pages/tabBar/template.uvue
pages/tabBar/template.uvue
+7
-0
pages/template/half-screen/half-screen.uvue
pages/template/half-screen/half-screen.uvue
+182
-0
未找到文件。
pages.json
浏览文件 @
b0d348fd
...
@@ -707,7 +707,16 @@
...
@@ -707,7 +707,16 @@
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
}
}
],
,{
"path"
:
"pages/template/half-screen/half-screen"
,
"style"
:
{
"navigationBarTitleText"
:
"半屏弹窗"
,
"enablePullDownRefresh"
:
false
}
}
],
"globalStyle"
:
{
"globalStyle"
:
{
"pageOrientation"
:
"portrait"
,
"pageOrientation"
:
"portrait"
,
"navigationBarTitleText"
:
"Hello uniapp x"
,
"navigationBarTitleText"
:
"Hello uniapp x"
,
...
...
pages/tabBar/template.uvue
浏览文件 @
b0d348fd
...
@@ -109,6 +109,13 @@
...
@@ -109,6 +109,13 @@
open: false,
open: false,
pages: [] as Page[]
pages: [] as Page[]
},
},
{
id: "half-screen",
url: "half-screen",
name: "半屏弹窗",
open: false,
pages: [] as Page[]
},
{
{
id: "drop-card",
id: "drop-card",
url: "drop-card",
url: "drop-card",
...
...
pages/template/half-screen/half-screen.uvue
0 → 100644
浏览文件 @
b0d348fd
<template>
<view class="page">
<text>TouchEvent还有细节需要优化,需支持拦截事件分发逻辑解决拖拽半屏窗口引起内容滚动的问题</text>
<button class="bottomButton" @click="switchHalfScreen(true)">打开弹窗</button>
<view ref="halfScreen" class="halfScreen" @touchstart="onHalfTouchStart" @touchmove="onHalfTouchMove" @touchend="onHalfTouchEnd">
<view class="halfTitle" >半屏弹窗标题</view>
<scroll-view ref="halfScroll" class="halfScroll" @scroll="onScroll" bounce="true">
<view v-for="(item,index) in list" :key="index" class="item">
half screen content-{{item}}
</view>
</scroll-view>
</view>
</view>
</template>
<script>
import ScrollEvent from 'io.dcloud.uniapp.runtime.ScrollEvent';
export default {
data() {
return {
list: ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15'],
totalHeight: 0, //总高度
halfMove: false, //是否Move,响应TouchMove
halfScreenY: 0, //响应TouchMove的起始点Y坐标
halfOffset: 0, //偏移的位置,translateY
halfHeight: 0, //高度
lastY: 0, //上次
lastY2: 0, //
bAnimation: false, //是否动画
halfNode: null as INode | null,
scrollNode: null as INode | null
}
},
methods: {
onHalfTouchStart(_:TouchEvent) {
this.halfNode?.style?.setProperty('transitionDuration', 0);
//console.log('Title TouchStart: ', e);
},
onHalfTouchMove(e:TouchEvent) {
if(this.bAnimation){//容错处理
return;
}
let top:number = this.scrollNode?.getAttribute('scrollTop') as number
let p = e.touches[0];
this.lastY2 = this.lastY;
this.lastY = p.screenY;
if(top <= 0.01 || this.halfMove){
if(this.halfScreenY == 0){
this.halfScreenY = p.screenY;
}
let offset = p.screenY-this.halfScreenY;
if(offset > 0){
this.halfMove = true;
this.halfNode?.style?.setProperty('transform','translateY('+offset+'px)');
this.halfOffset = offset;
}else if(this.lastY2>this.lastY && this.halfOffset>0){//容错触发向下滚动的误差
offset = this.halfScreenY-p.screenY;
if(offset>this.halfOffset){
offset = this.halfOffset;
}
this.halfNode?.style?.setProperty('transform','translateY('+offset+'px)');
this.halfOffset = offset;
}
}
//console.log('TouchMove', e.target);
},
onHalfTouchEnd(_:TouchEvent) {
if(this.bAnimation){//容错处理
return;
}
let top:number = this.scrollNode?.getAttribute('scrollTop') as number
let bHide = (this.halfHeight-this.halfOffset)<this.halfHeight/4;
if(bHide){
bHide = this.lastY2>0&&this.lastY2<=this.lastY;
}else if(top <= 0.01){
bHide = (this.lastY-this.lastY2)>3; //向下滑动计算加速度判断是否关闭,简单处理未考虑时间
}
if(bHide){
switchHalfScreen(false);
}else{
resumeHalfScreen();
}
},
onScroll(_: ScrollEvent) {
//console.log('onScroll: ', e);
},
switchHalfScreen(show:boolean) {
if(show&&('visible'==this.halfNode?.style?.getPropertyValue('visibility'))){//容错处理
console.log('qucik click button!!!');
return;
}
this.halfMove = false;
this.halfScreenY = 0;
this.halfOffset = 0;
let top = this.totalHeight;
let time = 300;
if(show){
top = this.totalHeight*30/100; //计算显示的位置
this.halfNode?.style?.setProperty('visibility','visible');
this.halfNode?.style?.setProperty('transitionTimingFunction','ease-in-out');
}else{
this.halfNode?.style?.setProperty('transitionTimingFunction','linear');
time *= (this.halfHeight/this.totalHeight); //计算关闭动画时间
}
this.halfNode?.style?.setProperty('transitionDuration', time.toFixed(0));
this.halfNode?.style?.setProperty('transitionProperty','top');
this.halfNode?.style?.setProperty('top', top.toFixed(0));
setTimeout(()=>{
if(!show){
this.halfNode?.style?.setProperty('visibility','hidden');
this.halfNode?.style?.setProperty('transitionDuration', 0);
this.halfNode?.style?.setProperty('transform','');
}
this.halfNode?.style?.setProperty('transitionProperty','');
this.bAnimation = false;
}, time)
this.bAnimation = true;
},
resumeHalfScreen() {
let time = 300;//(500*this.halfOffset/this.halfHeight).toFixed(0); //回弹动画时间
this.halfNode?.style?.setProperty('transitionDuration',time.toFixed(0));
this.halfNode?.style?.setProperty('transitionTimingFunction','ease-in-out');
this.halfNode?.style?.setProperty('transitionProperty','transform');
this.halfNode?.style?.setProperty('transform','translateY(0px)');
this.halfMove = false;
this.halfScreenY = 0;
this.halfOffset = 0;
setTimeout(()=>{
this.bAnimation = false;
}, time)
this.bAnimation = true;
}
},
onReady() {
this.halfNode = this.$refs['halfScreen'] as INode;
this.halfHeight = this.halfNode!.getBoundingClientRect().height;
this.scrollNode = this.$refs['halfScroll'] as INode;
this.totalHeight = uni.getWindowInfo().windowHeight;
this.halfNode?.style?.setProperty('top', this.totalHeight.toString());
},
// onResize() {
// this.halfHeight = this.halfNode!.getBoundingClientRect().height;
// this.totalHeight = uni.getWindowInfo().windowHeight;
// }
}
</script>
<style>
.page {
flex: 1;
background-color: darkgrey;
}
.bottomButton {
position: absolute;
width: 100%;
bottom: 0px;
}
.halfScreen {
position: absolute;
top: 100%;
width: 100%;
height: 70%;
transition-timing-function: ease-in-out; /*ease ease-in ease-out ease-in-out linear step-start step-end*/
transition-property: top;
transition-duration: 0;
visibility: hidden;
}
.halfTitle {
align-items: center;
justify-content: center;
height: 48px;
background-color: cornflowerblue;
border-radius: 10px 10px 0 0;
}
.halfScroll {
background-color: ghostwhite;
}
.item {
height: 100px;
}
</style>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录