Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
64293b25
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看板
提交
64293b25
编写于
7月 26, 2023
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化 模板示例scroll-fold-nav的性能
把头部区域封装成一个组件,在滚动时,直接修改该组件的data里边的scrollTop,这样可以将每次滚动触发的变化范围限定到该组件内
上级
506c9e15
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
192 addition
and
173 deletion
+192
-173
pages/template/scroll-fold-nav/scroll-fold-header/scroll-fold-header.uvue
...croll-fold-nav/scroll-fold-header/scroll-fold-header.uvue
+82
-0
pages/template/scroll-fold-nav/scroll-fold-nav.uvue
pages/template/scroll-fold-nav/scroll-fold-nav.uvue
+31
-96
pages/template/scroll-fold-nav2/scroll-fold-nav2.uvue
pages/template/scroll-fold-nav2/scroll-fold-nav2.uvue
+79
-77
未找到文件。
pages/template/scroll-fold-nav/scroll-fold-header/scroll-fold-header.uvue
0 → 100644
浏览文件 @
64293b25
<template>
<view class="top-box" :style="{height:(110 - (scrollTop>40?40:scrollTop) )+'px','background-color': 'rgba(255, 255, 255, '+(scrollTop*3>100?100:scrollTop*3)/100+')'}">
<view class="scroll-fold-nav"
:style="{'opacity': 1 -(scrollTop*3>100?100:scrollTop*3)/100}"
>
<view style="margin-left: 30px;">DCloud 为开发者而生</view>
</view>
<view @click="back" class="back" style="position: absolute;top:35px;left: 8px;">
<image src="/static/template/scroll-fold-nav/back.png" style="width: 20px;" mode="widthFix"></image>
</view>
<view class="search" @click="toSearchPage" :style="{
'width':maxSearchWidth - (scrollTop>40?40:scrollTop) +'rpx',
'top':0 - (scrollTop>40?40:scrollTop) +'px'
}">
<view style="flex-direction: row;">
<image src="/static/template/scroll-fold-nav/search.png" style="width: 15px;" mode="widthFix"></image>
<text class="search-tip-text">请输入你要搜索的内容</text>
</view>
<text class="search-btn">搜索</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
scrollTop: 0,
maxSearchWidth: 700
}
},
methods: {
toSearchPage(){
this.$emit('toSearchPage')
},
back(){
this.$emit('back')
}
}
}
</script>
<style>
.top-box {
position: fixed;
top: 0;
padding-top: 25px;
align-items: flex-end;
border-bottom: 1px solid #efefef;
}
.scroll-fold-nav {
height: 44px;
width: 750rpx;
justify-content: center;
}
.search {
background-color: #FFFFFF;
border: 1px solid #fbdf0d;
height: 35px;
border-radius: 100px;
margin: 0 25rpx;
padding: 8px;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.search-tip-text {
font-size: 12px;
color: #666;
}
.search-btn {
font-size: 12px;
background-color: #ff6900;
color: #FFF;
padding: 5px 8px;
border-radius: 100px;
}
</style>
pages/template/scroll-fold-nav/scroll-fold-nav.uvue
浏览文件 @
64293b25
...
@@ -10,120 +10,55 @@
...
@@ -10,120 +10,55 @@
</view>
</view>
</view>
</view>
</scroll-view>
</scroll-view>
<scroll-fold-header ref="header" @back="back" @toSearchPage="toSearchPage()"/>
<view class="top-box" :style="{height:(110 - (scrollTop>40?40:scrollTop) )+'px','background-color': 'rgba(255, 255, 255, '+(scrollTop*3>100?100:scrollTop*3)/100+')'}">
<view class="scroll-fold-nav"
:style="{'opacity': 1 -(scrollTop*3>100?100:scrollTop*3)/100}"
>
<view style="margin-left: 30px;">DCloud 为开发者而生</view>
</view>
<view @click="back" class="back" style="position: absolute;top:35px;left: 8px;">
<image src="/static/template/scroll-fold-nav/back.png" style="width: 20px;" mode="widthFix"></image>
</view>
<view class="search" @click="toSearchPage" :style="{
'width':searchWidth - (scrollTop>40?40:scrollTop) +'rpx',
'top':0 - (scrollTop>40?40:scrollTop) +'px'
}">
<view style="flex-direction: row;">
<image src="/static/template/scroll-fold-nav/search.png" style="width: 15px;" mode="widthFix"></image>
<text class="search-tip-text">请输入你要搜索的内容</text>
</view>
<text class="search-btn">搜索</text>
</view>
</view>
</view>
</view>
</template>
</template>
<script>
<script>
import ScrollEvent from 'io.dcloud.uniapp.runtime.ScrollEvent';
import ScrollEvent from 'io.dcloud.uniapp.runtime.ScrollEvent';
export default {
import scrollFoldHeader from './scroll-fold-header/scroll-fold-header.uvue';
export default {
components:{scrollFoldHeader},
data() {
data() {
return {
return {}
scrollTop: 0,
searchWidth: 700
}
},
},
methods: {
methods: {
onScroll(e : ScrollEvent) {
onScroll(e : ScrollEvent) {
this.scrollTop
= e.detail.scrollTop
(this.$refs['header'] as ComponentPublicInstance).$data['scrollTop']
= e.detail.scrollTop
},
},
back()
{
back()
{
// uni.navigateBack() // 这么写用不了
// uni.navigateBack() // 这么写用不了
// 这么写可以用
// 这么写可以用
uni.navigateBack({
uni.navigateBack({
success(result) {
success(result) {
console.log('navigateBack success', result.errMsg)
console.log('navigateBack success', result.errMsg)
},
},
fail(error) {
fail(error) {
console.log('navigateBack fail', error.errMsg)
console.log('navigateBack fail', error.errMsg)
},
},
complete(result) {
complete(result) {
console.log('navigateBack complete', result.errMsg)
console.log('navigateBack complete', result.errMsg)
},
},
})
})
},
// uni.switchTab({
toSearchPage() {
// url:'/pages/tabBar/template'
uni.showToast({
// })
title: '暂不支持',
icon: 'none'
},
});
toSearchPage(){
uni.showToast({
title: '暂不支持',
icon: 'none'
});
}
}
},
},
onLoad() {
onLoad() {}
}
}
}
</script>
</script>
<style>
<style>
.page {
.page {
flex: 1;
flex: 1;
background-color: #fbdf0d;
background-color: #fbdf0d;
}
}
.scroll-view {
.scroll-view {
flex: 1;
flex: 1;
}
.top-box {
position: fixed;
top: 0;
padding-top: 25px;
align-items: flex-end;
border-bottom: 1px solid #efefef;
}
.scroll-fold-nav {
height: 44px;
width: 750rpx;
justify-content: center;
}
.search {
background-color: #FFFFFF;
border: 1px solid #fbdf0d;
height: 35px;
border-radius: 100px;
margin: 0 25rpx;
padding: 8px;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.search-tip-text {
font-size: 12px;
color: #666;
}
.search-btn {
font-size: 12px;
background-color: #ff6900;
color: #FFF;
padding: 5px 8px;
border-radius: 100px;
}
}
</style>
</style>
\ No newline at end of file
pages/template/scroll-fold-nav2/scroll-fold-nav2.uvue
浏览文件 @
64293b25
...
@@ -11,106 +11,106 @@
...
@@ -11,106 +11,106 @@
</view>
</view>
</scroll-view>
</scroll-view>
<view ref="top-box" class="top-box" style="height:110px;background-color:rgba(255,255,255,0)">
<view ref="top-box" class="top-box" style="height:110px;background-color:rgba(255,255,255,0)">
<view ref="scroll-fold-nav" class="scroll-fold-nav">
<view ref="scroll-fold-nav" class="scroll-fold-nav">
<view style="margin-left: 30px;">DCloud 为开发者而生</view>
<view style="margin-left: 30px;">DCloud 为开发者而生</view>
</view>
</view>
<view @click="back" class="back" style="position: absolute;top:35px;left: 8px;">
<view @click="back" class="back" style="position: absolute;top:35px;left: 8px;">
<image src="/static/template/scroll-fold-nav/back.png" style="width: 20px;" mode="widthFix"></image>
<image src="/static/template/scroll-fold-nav/back.png" style="width: 20px;" mode="widthFix"></image>
</view>
</view>
<view ref="search" class="search" @click="toSearchPage" style="width:700rpx;top:0px">
<view ref="search" class="search" @click="toSearchPage" style="width:700rpx;top:0px">
<view style="flex-direction: row;">
<view style="flex-direction: row;">
<image src="/static/template/scroll-fold-nav/search.png" style="width: 15px;" mode="widthFix"></image>
<image src="/static/template/scroll-fold-nav/search.png" style="width: 15px;" mode="widthFix"></image>
<text class="search-tip-text">请输入你要搜索的内容</text>
<text class="search-tip-text">请输入你要搜索的内容</text>
</view>
</view>
<text class="search-btn">搜索</text>
<text class="search-btn">搜索</text>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
</template>
<script>
<script>
import ScrollEvent from 'io.dcloud.uniapp.runtime.ScrollEvent';
import ScrollEvent from 'io.dcloud.uniapp.runtime.ScrollEvent';
export default {
export default {
data() {
data() {
return {
return {
scrollTop: 0,
scrollTop: 0,
searchWidth: 700,
searchWidth: 700,
searchNode: null as INode|null,
searchNode: null as INode | null,
boxNode: null as INode|null,
boxNode: null as INode | null,
navNode: null as INode|null
navNode: null as INode | null
}
}
},
},
methods: {
methods: {
onScroll(e : ScrollEvent) {
onScroll(e : ScrollEvent) {
let scrollTop = e.detail.scrollTop
let scrollTop = e.detail.scrollTop
this.boxNode?.style?.setProperty('height', (110 - (scrollTop>40?40:scrollTop) )+'px');
this.boxNode?.style?.setProperty('height', (110 - (scrollTop > 40 ? 40 : scrollTop)) + 'px');
this.boxNode?.style?.setProperty('background-color', 'rgba(255, 255, 255, '+(scrollTop*3>100?100:scrollTop*3)/100+')');
this.boxNode?.style?.setProperty('background-color', 'rgba(255, 255, 255, ' + (scrollTop * 3 > 100 ? 100 : scrollTop * 3) / 100 + ')');
this.navNode?.style?.setProperty('opacity', 1 - (scrollTop*3>100?100:scrollTop*3)/100.0);
this.navNode?.style?.setProperty('opacity', 1 - (scrollTop * 3 > 100 ? 100 : scrollTop * 3) / 100.0);
this.searchNode?.style?.setProperty('width', 700 - (scrollTop>40?40:scrollTop) +'rpx');
this.searchNode?.style?.setProperty('width', 700 - (scrollTop > 40 ? 40 : scrollTop) + 'rpx');
this.searchNode?.style?.setProperty('top', 0 - (scrollTop>40?40:scrollTop) +'px');
this.searchNode?.style?.setProperty('top', 0 - (scrollTop > 40 ? 40 : scrollTop) + 'px');
this.scrollTop = scrollTop;
this.scrollTop = scrollTop;
},
},
back()
{
back()
{
// uni.navigateBack() // 这么写用不了
// uni.navigateBack() // 这么写用不了
// 这么写可以用
// 这么写可以用
uni.navigateBack({
uni.navigateBack({
success(result) {
success(result) {
console.log('navigateBack success', result.errMsg)
console.log('navigateBack success', result.errMsg)
},
},
fail(error) {
fail(error) {
console.log('navigateBack fail', error.errMsg)
console.log('navigateBack fail', error.errMsg)
},
},
complete(result) {
complete(result) {
console.log('navigateBack complete', result.errMsg)
console.log('navigateBack complete', result.errMsg)
},
},
})
})
// uni.switchTab({
// uni.switchTab({
// url:'/pages/tabBar/template'
// url:'/pages/tabBar/template'
// })
// })
},
},
toSearchPage()
{
toSearchPage()
{
uni.showToast({
uni.showToast({
title: '暂不支持',
title: '暂不支持',
icon: 'none'
icon: 'none'
});
});
}
}
},
},
onLoad() {
onLoad() {
},
},
onReady() {
onReady() {
this.searchNode = this.$refs['search'] as INode;
this.searchNode = this.$refs['search'] as INode;
this.boxNode = this.$refs['top-box'] as INode;
this.boxNode = this.$refs['top-box'] as INode;
this.navNode = this.$refs['scroll-fold-nav'] as INode;
this.navNode = this.$refs['scroll-fold-nav'] as INode;
}
}
}
}
</script>
</script>
<style>
<style>
.page {
.page {
flex: 1;
flex: 1;
background-color: #fbdf0d;
background-color: #fbdf0d;
}
}
.scroll-view {
.scroll-view {
flex: 1;
flex: 1;
}
}
.top-box {
.top-box {
position: fixed;
position: fixed;
top: 0;
top: 0;
padding-top: 25px;
padding-top: 25px;
align-items: flex-end;
align-items: flex-end;
border-bottom: 1px solid #efefef;
border-bottom: 1px solid #efefef;
}
}
.scroll-fold-nav {
.scroll-fold-nav {
height: 44px;
height: 44px;
width: 750rpx;
width: 750rpx;
justify-content: center;
justify-content: center;
}
}
.search {
.search {
...
@@ -118,21 +118,23 @@
...
@@ -118,21 +118,23 @@
border: 1px solid #fbdf0d;
border: 1px solid #fbdf0d;
height: 35px;
height: 35px;
border-radius: 100px;
border-radius: 100px;
margin: 0 25rpx;
margin: 0 25rpx;
padding: 8px;
padding: 8px;
flex-direction: row;
flex-direction: row;
align-items: center;
align-items: center;
justify-content: space-between;
justify-content: space-between;
}
}
.search-tip-text {
font-size: 12px;
.search-tip-text {
color: #666;
font-size: 12px;
}
color: #666;
.search-btn {
}
font-size: 12px;
background-color: #ff6900;
.search-btn {
color: #FFF;
font-size: 12px;
padding: 5px 8px;
background-color: #ff6900;
border-radius: 100px;
color: #FFF;
padding: 5px 8px;
border-radius: 100px;
}
}
</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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录