提交 445e1603 编写于 作者: 雪洛's avatar 雪洛

fix: 修正样式错误

上级 40efebdd
<template> <template>
<scroll-view @scroll="onScroll" class="scroll-view" rebound="false"> <scroll-view @scroll="onScroll" class="scroll-view" rebound="false">
<!--#ifdef APP--> <!--#ifdef APP-->
<view class="height-seat" style="height: 125px;"> <view class="height-seat" style="height: 125px;">
<!-- 垫高专用 --> <!-- 垫高专用 -->
</view> </view>
<!--#endif--> <!--#endif-->
<!--#ifdef WEB--> <!--#ifdef WEB-->
...@@ -10,209 +10,210 @@ ...@@ -10,209 +10,210 @@
<!-- 垫高专用 --> <!-- 垫高专用 -->
</view> </view>
<!--#endif--> <!--#endif-->
<view class="content"> <view class="content">
<view class="content-item"> <view class="content-item">
<text class="text">1. 当前示例监听了 scroll-view 的 scroll 事件 ,滚动页面实时监听scrollTop。</text> <text class="text">1. 当前示例监听了 scroll-view 的 scroll 事件 ,滚动页面实时监听scrollTop。</text>
<text class="text">2. 使用 ref 直接获取元素的节点,并在 scroll 事件中通过节点的 setProperty <text class="text">2. 使用 ref 直接获取元素的节点,并在 scroll 事件中通过节点的 setProperty
方法来修改搜索导航栏的高度、位置和背景颜色等样式,从而达到滚动折叠的效果。</text> 方法来修改搜索导航栏的高度、位置和背景颜色等样式,从而达到滚动折叠的效果。</text>
<text class="text">3. 请向上\向下滚动页面观察效果。</text> <text class="text">3. 请向上\向下滚动页面观察效果。</text>
</view> </view>
<view class="content-item" v-for="(item,index) in 20" :key="index"> <view class="content-item" v-for="(item,index) in 20" :key="index">
<text class="text">content-{{item}}</text> <text class="text">content-{{item}}</text>
</view> </view>
</view> </view>
<view ref="top-box" class="top-box"> <view ref="top-box" class="top-box">
<view ref="scroll-fold-nav" class="scroll-fold-nav"> <view ref="scroll-fold-nav" class="scroll-fold-nav">
<view class="nav-title">DCloud 为开发者而生</view> <view class="nav-title">DCloud 为开发者而生</view>
</view> </view>
<view @click="back" class="nav-back"> <view @click="back" class="nav-back">
<image class="back-img" src="/static/template/scroll-fold-nav/back.png" mode="widthFix"></image> <image class="back-img" src="/static/template/scroll-fold-nav/back.png" mode="widthFix"></image>
</view> </view>
<view ref="search" class="search" @click="toSearchPage"> <view ref="search" class="search" @click="toSearchPage">
<view class="search-inner"> <view class="search-inner">
<image class="search-img" src="/static/template/scroll-fold-nav/search.png" mode="widthFix"></image> <image class="search-img" src="/static/template/scroll-fold-nav/search.png" 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>
</scroll-view> </scroll-view>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
statusBarHeight: 35, statusBarHeight: 35,
scrollTop: 0, scrollTop: 0,
searchWidth: 700, searchWidth: 700,
searchNode: null as UniElement | null, searchNode: null as UniElement | null,
boxNode: null as UniElement | null, boxNode: null as UniElement | null,
navNode: null as UniElement | null navNode: null as UniElement | null
} }
}, },
onLoad() { }, onLoad() { },
onReady() { onReady() {
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight ?? 35; this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight ?? 35;
this.searchNode = this.$refs['search'] as UniElement; this.searchNode = this.$refs['search'] as UniElement;
this.boxNode = this.$refs['top-box'] as UniElement; this.boxNode = this.$refs['top-box'] as UniElement;
this.navNode = this.$refs['scroll-fold-nav'] as UniElement; this.navNode = this.$refs['scroll-fold-nav'] as UniElement;
}, },
methods: { methods: {
onScroll(e : ScrollEvent) { onScroll(e : ScrollEvent) {
let scrollTop = e.detail.scrollTop let scrollTop = e.detail.scrollTop
// #ifdef APP // #ifdef APP
const originalBoxHeight = 125 const originalBoxHeight = 125
// #else // #else
const originalBoxHeight = 90 const originalBoxHeight = 90
// #endif // #endif
this.boxNode?.style?.setProperty('height', (originalBoxHeight - (scrollTop > 35 ? 35 : scrollTop)) + 'px'); this.boxNode?.style?.setProperty('height', (originalBoxHeight - (scrollTop > 35 ? 35 : scrollTop)) + 'px');
this.boxNode?.style?.setProperty('background-color', 'rgba(255, 255, 255, ' + (scrollTop * 3 > 100 ? 100 : scrollTop * 3) / 100.0 + ')'); this.boxNode?.style?.setProperty('background-color', 'rgba(255, 255, 255, ' + (scrollTop * 3 > 100 ? 100 : scrollTop * 3) / 100.0 + ')');
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'
}); });
} }
}, },
} }
</script> </script>
<style> <style>
.page { .page {
flex: 1; flex: 1;
background-color: #fbdf0d; background-color: #fbdf0d;
} }
.scroll-view { .scroll-view {
flex: 1; flex: 1;
} }
.height-seat { .height-seat {
height: 110px; height: 110px;
/* background-color: #fbdf0d; */ /* background-color: #fbdf0d; */
} }
.content { .content {
padding: 5px 15px; padding: 5px 15px;
background-color: #f5f5f5; background-color: #f5f5f5;
} }
.content-item { .content-item {
padding: 15px; padding: 15px;
margin: 5px 0; margin: 5px 0;
background-color: #fff; background-color: #fff;
border-radius: 5px; border-radius: 5px;
} }
.text { .text {
font-size: 14px; font-size: 14px;
color: #666; color: #666;
line-height: 20px; line-height: 20px;
} }
.top-box { .top-box {
position: fixed; position: fixed;
top: 0; top: 0;
align-items: flex-end; width: 100%;
align-items: flex-end;
border-bottom: 1px solid #efefef; border-bottom: 1px solid #efefef;
/* #ifdef APP */ /* #ifdef APP */
height: 125px; height: 125px;
padding-top: 35px; padding-top: 35px;
/* #else */ /* #else */
height: 90px; height: 90px;
/* #endif */ /* #endif */
background-color: rgba(255, 255, 255, 0); background-color: rgba(255, 255, 255, 0);
background-color: aliceblue; background-color: aliceblue;
} }
.scroll-fold-nav { .scroll-fold-nav {
height: 44px; height: 44px;
width: 375px; width: 375px;
justify-content: center; justify-content: center;
} }
.nav-title { .nav-title {
margin-left: 30px; margin-left: 30px;
} }
.nav-back { .nav-back {
position: absolute; position: absolute;
/* #ifdef APP */ /* #ifdef APP */
top: 46px; top: 46px;
/* #else */ /* #else */
top: 11px; top: 11px;
/* #endif */ /* #endif */
left: 8px; left: 8px;
} }
.nav-back .back-img { .nav-back .back-img {
width: 18px; width: 18px;
margin-top: 2px; margin-top: 2px;
} }
.search { .search {
background-color: #FFFFFF; background-color: #FFFFFF;
border: 1px solid #fbdf0d; border: 1px solid #fbdf0d;
height: 35px; height: 35px;
border-radius: 100px; border-radius: 100px;
margin: 0 12px; margin: 0 12px;
padding: 8px; padding: 8px;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
width: 350px; width: 350px;
top: 0px; top: 0px;
} }
.search-inner { .search-inner {
margin-top: 2px; margin-top: 2px;
flex-direction: row; flex-direction: row;
} }
.search-inner .search-img { .search-inner .search-img {
width: 15px; width: 15px;
} }
.search-tip-text { .search-tip-text {
font-size: 12px; font-size: 12px;
color: #666; color: #666;
} }
.search-btn { .search-btn {
font-size: 12px; font-size: 12px;
background-color: #ff6900; background-color: #ff6900;
color: #FFF; color: #FFF;
padding: 5px 8px; padding: 5px 8px;
border-radius: 100px; border-radius: 100px;
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册