Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Accustomed_
hello uni-app x
提交
06538f77
H
hello uni-app x
项目概览
Accustomed_
/
hello uni-app x
与 Fork 源项目一致
Fork自
DCloud / hello uni-app x
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
06538f77
编写于
8月 17, 2023
作者:
M
mehaotian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pref: 优化吸顶示例样式
上级
e9e193a7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
115 addition
and
101 deletion
+115
-101
pages/template/scroll-sticky/scroll-sticky.uvue
pages/template/scroll-sticky/scroll-sticky.uvue
+115
-101
未找到文件。
pages/template/scroll-sticky/scroll-sticky.uvue
浏览文件 @
06538f77
<template>
<scroll-view :scroll-y="true" @scroll="onScroll" class="page">
<view v-for="(item,index) in list" :key="index" class="item">
first content-{{item}}
</view>
<view class="content-item">
<text class="text">向上滑动页面,体验元素吸顶效果。</text>
</view>
<view v-for="(item,index) in list" :key="index" class="content-item">
<text class="text">first content-{{item}}</text>
</view>
<!-- <view ref="sticky" class="search" @click="" :style="{
'transform': 'translateY('+stickyTran+'px)'
}"> -->
<view ref="sticky" class="search" @click="">
<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 ref="sticky" class="search" @click="" :style="{
'transform': 'translateY('+stickyTran+'px)'
}"> -->
<view ref="sticky" class="search" @click="">
<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 v-for="(item,index) in list" :key="index" class="
item">
second content-{{item}}
</view>
<view v-for="(item,index) in list" :key="index" class="content-
item">
<text class="text">second content-{{item}}</text>
</view>
<view v-for="(item,index) in list" :key="index" class="
item">
second content-{{item}}
</view>
<view v-for="(item,index) in list" :key="index" class="content-
item">
<text class="text">second content-{{item}}</text>
</view>
</scroll-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'],
stickyTop: 0,
stickyTran: 0,
scrollTop: 0,
stickyNode: null as INode | null
}
},
methods: {
onScroll(e : ScrollEvent) {
if(e.detail.scrollTop > this.stickyTop){
let stickyTran = e.detail.scrollTop - this.stickyTop;
if(stickyTran!=this.stickyTran){
this.stickyNode?.style?.setProperty('transform','translateY('+stickyTran+'px)');
}
this.stickyTran = stickyTran;
}else{
this.stickyNode?.style?.setProperty('transform','');
this.stickyTran = 0;
}
},
back(){
uni.navigateBack({
success(result) {
console.log('navigateBack success', result.errMsg)
},
fail(error) {
console.log('navigateBack fail', error.errMsg)
},
complete(result) {
console.log('navigateBack complete', result.errMsg)
},
})
}
},
onLoad() {
},
onReady() {
this.stickyNode = this.$refs['sticky'] as INode;
// let rect = this.stickyNode?.getBoundingClientRect();
// this.stickyTop = rect?.top;
//this.stickyTop = this.stickyNode?.getBoundingClientRect()?.top;
let rect = (this.$refs['sticky'] as INode).getBoundingClientRect();
this.stickyTop = rect.top;
<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'],
stickyTop: 0,
stickyTran: 0,
scrollTop: 0,
stickyNode: null as INode | null
}
},
methods: {
onScroll(e : ScrollEvent) {
if (e.detail.scrollTop > this.stickyTop) {
let stickyTran = e.detail.scrollTop - this.stickyTop;
if (stickyTran != this.stickyTran) {
this.stickyNode?.style?.setProperty('transform', 'translateY(' + stickyTran + 'px)');
}
this.stickyTran = stickyTran;
} else {
this.stickyNode?.style?.setProperty('transform', '');
this.stickyTran = 0;
}
},
back() {
uni.navigateBack({
success(result) {
console.log('navigateBack success', result.errMsg)
},
fail(error) {
console.log('navigateBack fail', error.errMsg)
},
complete(result) {
console.log('navigateBack complete', result.errMsg)
},
})
}
},
onLoad() {
},
onReady() {
this.stickyNode = this.$refs['sticky'] as INode;
// let rect = this.stickyNode?.getBoundingClientRect();
// this.stickyTop = rect?.top;
//this.stickyTop = this.stickyNode?.getBoundingClientRect()?.top;
let rect = (this.$refs['sticky'] as INode).getBoundingClientRect();
this.stickyTop = rect.top;
}
}
}
</script>
<style>
.page {
flex: 1;
background-color: azure;
}
.item {
height: 100px;
}
.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;
z-index: 100;
}
.search-tip-text {
font-size: 12px;
color: #666;
}
.search-btn {
font-size: 12px;
background-color: #ff6900;
color: #FFF;
padding: 5px 8px;
border-radius: 100px;
}
.page {
flex: 1;
padding: 5px 15px;
background-color: #f5f5f5;
}
.content-item {
padding: 15px;
margin: 5px 0;
background-color: #fff;
border-radius: 5px;
}
.text {
font-size: 14px;
color: #666;
line-height: 20px;
}
.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;
z-index: 100;
}
.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>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录