scroll-fold-header.uvue 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<template>
	<view class="top-box" :style="headBoxStyle">
		<view class="scroll-fold-nav" :style="titleStyle">
			<view class="nav-title">DCloud 为开发者而生</view>
		</view>
		<view @click="back" class="nav-back">
			<image class="back-img" src="/static/template/scroll-fold-nav/back.png" 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 class="search-inner">
				<image class="search-img" src="/static/template/scroll-fold-nav/search.png" mode="widthFix"></image>
				<text class="search-tip-text">请输入你要搜索的内容</text>
			</view>
			<text class="search-btn">搜索</text>
		</view>
	</view>
</template>
21

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
<script>
	export default {
		data() {
			return {
				scrollTop: 0,
				maxSearchWidth: 700
			}
		},
		computed: {
			// 修理导航栏头部高度和背景颜色变化
			headBoxStyle() : string {
				const scrollTop = this.scrollTop
				let style = `height:  ${110 - (scrollTop > 40 ? 40 : scrollTop)}px;background-color: rgba(255, 255, 255, ${(scrollTop * 3 > 100 ? 100 : scrollTop * 3) / 100})`
		
				return style
			},
			// 处理导航栏标题透明度变化
			titleStyle() : string {
				const scrollTop = this.scrollTop
				let style = `opacity: ${1 - (scrollTop * 3 > 100 ? 100 : scrollTop * 3) / 100}`
				return style
			}
		},
		methods: {
			toSearchPage() {
				this.$emit('toSearchPage')
			},
			back() {
				this.$emit('back')
			}
		}
	}
</script>
55

56 57 58 59 60 61 62 63
<style>
	.top-box {
		position: fixed;
		top: 0;
		padding-top: 25px;
		align-items: flex-end;
		border-bottom: 1px solid #efefef;
	}
64

65 66 67 68 69
	.scroll-fold-nav {
		height: 44px;
		width: 750rpx;
		justify-content: center;
	}
70

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
	.nav-title {
		margin-left: 30px;
	}

	.nav-back {
		position: absolute;
		top: 35px;
		left: 8px;
	}

	.nav-back .back-img {
		width: 18px;
		margin-top: 2px;
	}

	.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-inner {
		margin-top: 2px;
		flex-direction: row;
	}

	.search-inner .search-img {
		width: 15px;
	}

	.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>