123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <template>
- <view
- class="ylx-page-header row"
- :style="{
- height: navigationBarHeight+statusBarHeight+'px',
- paddingTop: statusBarHeight+'px',
- backgroundColor: 'rgba(255,255,255, '+headerOpacity+')'
- }"
- >
- <view class="btn center" @click="navBack">
- <text class="yticon icon-xiangzuo" :class="{dark: headerOpacity < 0.5}"></text>
- </view>
- <view class="cen center">
- <view
- class="cen-item"
- :class="{active: index === currentAnchor}"
- :style="{opacity: headerOpacity}"
- v-for="(item, index) in anchorList"
- :key="index"
- @click="navToAnchor(index)"
- >
- <text>{{ item.name }}</text>
- </view>
- </view>
- <view class="btn"></view>
- </view>
- </template>
- <script>
- let _disableScroll = false;
- export default {
- name: 'ProductPageHeader',
- data() {
- return {
- headerOpacity: 0,
- currentAnchor: 0,
- anchorList: [
- {id: 1, name: '视频讲解', top: 0},
- {id: 2, name: '解析文档', top: 0},
- {id: 3, name: '文档下载', top: 0},
- ]
- };
- },
- props: {
-
- },
- computed: {
- statusBarHeight(){
- return this.systemInfo.statusBarHeight;
- },
- navigationBarHeight(){
- return this.systemInfo.navigationBarHeight;
- }
- },
- methods: {
- //转到锚点
- navToAnchor(index){
- const {headerOpacity, anchorList, statusBarHeight, navigationBarHeight} = this;
- if(this.headerOpacity == 0){
- return;
- }
- _disableScroll = true;
- uni.pageScrollTo({
- scrollTop: anchorList[index].top - 1,
- duration: 200
- })
- this.currentAnchor = index;
- setTimeout(()=>{
- _disableScroll = false;
- }, 400)
- },
- pageScroll(e){
- //头部渐变
- this.headerOpacity = e.scrollTop/150;
- //锚点切换
- if(_disableScroll){
- return;
- }
- const {currentAnchor, anchorList} = this;
- const cur = e.scrollTop >= anchorList[2].top ? 2 : e.scrollTop >= anchorList[1].top ? 1:0;
- if(cur !== currentAnchor){
- this.currentAnchor = cur;
- }
- },
- navBack(){
- uni.navigateBack();
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .ylx-page-header{
- position: fixed;
- left: 0;
- top: 100rpx;
- z-index: 90;
- justify-content: space-between;
- width: 100%;
- }
-
- .btn{
- width: 80rpx;
- }
-
- .icon-xiangzuo{
- width: 52rpx;
- height: 52rpx;
- border-radius: 100rpx;
- font-size: 36rpx;
- color: #333;
- text-align: center;
- line-height: 52rpx;
-
- &.dark{
- background-color: rgba(0,0,0,.5);
- color: #fff;
- }
- }
-
- .cen{
- flex: 1;
- height: 100%;
- position: relative;
-
- .cen-item{
- width: 50px;
- height: 36px;
- font-size: 15px;
- color: #333;
- text-align: center;
- line-height: 36px;
- position: relative;
- }
-
- .active{
- font-size: 17px;
- font-weight: 700;
-
- &:after{
- position: absolute;
- left: 50%;
- bottom: 0;
- transform: translateX(-50%);
- content: '';
- width: 30px;
- height: 2px;
- background-color: $base-color;
- border-radius: 10rpx;
- }
- }
- }
- </style>
|