ionic3 自定义页面头部

仿写一个上拉透明到白色的动画

html

<ion-header no-border>
	<!-- 返回和分享 -->
	<div #pnavs class="topspan">
		<div class="returnimg" (click)="goBack()">
			<img src="../../assets/imgs/return.png" alt="">
		</div>
		<div class="shareimg" (click)="appShare()">
			<img src="../../assets/imgs/share.png" alt="">
		</div>
	</div>
</ion-header>
<!-- 记得在ion-content 加上 如下 -->
<ion-content catch-view="false" fullscreen (ionScroll)="scrollEvent($event)">

scss

ion-header {

        .topspan {
            width: 100% !important;
            height: 48px !important;
            background-color: rgba(255, 255, 255, 0);
            position: fixed;
            // top: 0;
            // top: 20px; //app加20px;
            left: 0;
            z-index: 1231231;

            .returnimg {
                width: 9px;
                height: 27.3px;
                position: absolute;
                top: 8.8px;
                left: 22.5px;
                display: flex;
                justify-content: center;
                align-items: center;

                img {
                    width: 8px;
                    height: 18px;
                    font-size: 0;
                }
            }

            .shareimg {
                width: 25px !important;
                height: 27.3px;
                position: absolute;
                right: 22.5px;
                top: 8.8px;
                display: flex;
                justify-content: center;
                align-items: center;

                img {
                    width: 18px;
                    height: 18px;
                    font-size: 0;
                }
            }
        }
    }

ts

import { ... ViewChild } from '@angular/core';
import { ... Content } from 'ionic-angular';
.
.
.
@ViewChild('pnavs') sticknavs;
@ViewChild(Content) content: Content;
.
.
.
//页面滑动触发事件
scrollEvent(e) {
    if (e.scrollTop < 10) {
        this.sticknavs.nativeElement.style.background = "rgba(255,255,255,0)";
        this.sticknavs.nativeElement.style.opacity = 1;
    } else if (e.scrollTop > 10 && e.scrollTop < 375) {
        let opacity = (375 - e.scrollTop) / 375;
        this.sticknavs.nativeElement.style.opacity = 1 - opacity;
    } else {
	     this.sticknavs.nativeElement.style.opacity = 1;
        this.sticknavs.nativeElement.style.background = "rgba(255,255,255,1)";
	 }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值