标题栏的渐变效果

  使用到的相关装饰器、Class以及相关方法:@Input、@ViewChild、Content、ionViewDidLoad

  ① @Input 装饰器:用来获取页面元素自定义属性值。

    

<app-header search-show="false" title="发现"></app-header> 

在页面 finder.html 页面中,通过调用的控件,并且定义了两个属性 search-show、title; 
 title : String = '';//默认标题
@Input("search-show")
set setDefaultSearchStatus(value:boolean){ }
@Input("title")
set setTitle(value:String){
this.title = value;
}
在组件关联的 .ts 页面中,通过使用 @Input 装饰器,并且实现其 set 方法,完成对 title 的赋值。

    通过使用 {{title}},完成对页面数据的绑定

    

  ②通过 @Viewchild 和引用 Content 实现对 scroll 监听,Events 的订阅者模式完成数据的回调

    在 finder.js 中,重载 ionViewDidLoad 方法

import { IonicPage, Content, Events} from 'ionic-angular';
import { Component, ViewChild } from '@angular/core';
@IonicPage()
@Component({
templateUrl:'./finder.html',
styles:['./finder.scss']
}) export class FinderPage{
constructor(private events:Events){ }
// 页面监听
@ViewChild(Content)content : Content;
ionViewDidLoad(){
this.content.ionScroll.subscribe(($event:any)=>{
this.events.publish("finder_scroll_status",[$event.scrollTop]);//finder_scroll_status 用于回调接收
}) }

    在 app-header.ts 中通过 Events 完成接收:

 constructor(private events:Events,private ngzone :NgZone){
// 获取【发现】页面中 scroll 监听数据
// ngzone 用来进行页面重构
this.events.subscribe('finder_scroll_status',(params)=>{// subscribe 订阅者模式,完成就收回调数据 })
}

  ③渐变效果的实现:通过回调得到的页面 scroll 的移动位置,计算标题的 opacity 元素属性,通过改变 opacity 来实现渐变效果。因为要动态的改变页面样式,所以还需要引用 ngZone 服务,用来及时的更新页面

    app-header.ts完整代码:

import { Component, Input, ViewChild, NgZone } from '@angular/core';
import { IonicPage, Events } from '../../../node_modules/ionic-angular'; @IonicPage()
@Component({
selector: 'app-header',
templateUrl: 'app-header.html',
styles:['./app-header.scss']
})
export class AppHeaderComponent { title : String = '';//默认标题
private search_nav_height = ;//搜索框高度
private normal_title_nav = {//普通的标题栏
opacity:,
opacityChild:
};
private normal_search_nav = {//普通的搜索栏
opacity:
};
@Input("search-show")
set setDefaultSearchStatus(value:boolean){ }
@Input("title")
set setTitle(value:String){
this.title = value;
}
@ViewChild('normalSearchNav') normal_search_el;//获取页面普通搜索框
@ViewChild('normalTitleNav') normal_title_el;//普通的 title constructor(private events:Events,private ngzone :NgZone){
// 获取【发现】页面中 scroll 监听数据
// ngzone 用来进行页面重构
this.events.subscribe('finder_scroll_status',(params)=>{
if(this.normal_search_el && this.normal_search_el.nativeElement.offsetHeight>){
this.search_nav_height = this.normal_search_el.nativeElement.offsetHeight;
}
this.ngzone.run(()=>{
if(this.search_nav_height >= params[] ){//掩藏标题栏 || 显示search
if(this.normal_search_nav.opacity >= ){
this.normal_search_nav.opacity = - (params[]/this.search_nav_height);
this.normal_search_el.nativeElement.style.display = ''; this.normal_title_nav.opacity = (params[]/this.search_nav_height);
this.normal_title_nav.opacityChild = ;
}
}
if(this.search_nav_height < params[]){//掩藏搜索栏 || 显示title
this.normal_search_nav.opacity = ;
this.normal_title_nav.opacity = ;
this.normal_search_el.nativeElement.style.display = 'none'; if(params[]-this.search_nav_height >= this.search_nav_height/){//子元素的一个延时显示
this.normal_title_nav.opacityChild = ;
} } })
})
} }

    app-header.html完整代码:

<!-- Generated template for the AppHeaderComponent component -->
<ion-grid class="app-grid-header" no-padding>
<ion-row class="margin-6 zindex-999" no-padding #normalSearchNav>
<ion-col col->
<ion-input no-padding [style.opacity]="normal_search_nav.opacity" class="bg-white border-r-4 bg-search" type="text" placeholder="得到搜索"></ion-input>
</ion-col>
<ion-col col->
<i class="i-png-down i-png"></i>
</ion-col>
</ion-row>
<ion-row class="bg-white absolute width" [style.opacity]="normal_title_nav.opacity" padding #normalTitleNav>
<ion-col [style.opacity]="normal_title_nav.opacityChild" col->
<i class="btn-search i-png"></i>
</ion-col>
<ion-col [style.opacity]="normal_title_nav.opacityChild" col->
<span class="span-center text-center font-w-6 font-middle">{{title}}</span>
</ion-col>
<ion-col [style.opacity]="normal_title_nav.opacityChild" col->
<i class="btn-down i-png"></i>
</ion-col>
</ion-row>
</ion-grid>

 先这样吧~

Ionic3,装饰器(@Input、@ViewChild)以及使用 Events 实现数据回调中的相关用法(五)的更多相关文章

  1. Angular 之装饰器@Input

    Input 一个装饰器,用来把某个类字段标记为输入属性,并提供配置元数据. 该输入属性会绑定到模板中的某个 DOM 属性.当变更检测时,Angular 会自动使用这个 DOM 属性的值来更新此数据属性 ...

  2. 20.python笔记之装饰器

    装饰器 装饰器是函数,只不过该函数可以具有特殊的含义,装饰器用来装饰函数或类,使用装饰器可以在函数执行前和执行后添加相应操作. 装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插 ...

  3. Python-迭代器&生成器&装饰器&软件目录结构规范-Day5

    目录Day-Python-迭代器&生成器 21.生成器 21.1.生成器引入 21.2.生成器作用 31.3.创建生成器的方法 31.4.用函数来实现复杂的生成器 51.5.把函数变成生成器通 ...

  4. 【Angular专题】 (3)装饰器decorator,一块语法糖

    目录 一. Decorator装饰器 二. Typescript中的装饰器 2.1 类装饰器 2.2 方法装饰器 2.3 访问器装饰器 2.4 属性装饰器 2.5 参数装饰器 三. 用ES5代码模拟装 ...

  5. 装饰器模式&&ES7 Decorator 装饰器

    装饰器模式(Decorator Pattern)允许向一个现有的对象动态添加新的功能,同时又不改变其结构.相比JavaScript中通过鸡肋的继承来给对象增加功能来说,装饰器模式相比生成子类更为灵活. ...

  6. Python全栈开发记录_第五篇(装饰器)

    单独记录装饰器这个知识点是因为这个知识点是非常重要的,必须掌握的(代码大约150行). 了解装饰器之前要知道三个知识点 作用域,上一篇讲到过顺序是L->E->G->B 高阶函数: 满 ...

  7. Python之路(第十一篇)装饰器

    一.什么是装饰器? 装饰器他人的器具,本身可以是任意可调用对象,被装饰者也可以是任意可调用对象. 强调装饰器的原则:1 不修改被装饰对象的源代码 2 不修改被装饰对象的调用方式 装饰器的目标:在遵循1 ...

  8. day6 装饰器总结

    装饰器:开放封闭原则,为一个函数加上新的功能,不改变原函数,不改变调用方式 def fun2(wtf): def fun3(): print('i am pythoner!!! ') wtf() re ...

  9. Python基础4 迭代器,生成器,装饰器,Json和pickle 数据序列化

    本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 1.列表生成式,迭代器&生成器 列表生成式 孩子,我现在有个需 ...

随机推荐

  1. Yii2在Form中处理短信验证码的Validator,耦合度最低的短信验证码验证方式

    短信验证码在目前大多数web应用中都会有,本文介绍一个基于Yii2 Validator方式的验证码验证方式. 在其他文章中看到的方式大多比较难做到一次封装,多次重用. 使用此方式的好处自然不用多说,V ...

  2. CodeForces 690C2 Brain Network (medium)(树上DP)

    题意:给定一棵树中,让你计算它的直径,也就是两点间的最大距离. 析:就是一个树上DP,用两次BFS或都一次DFS就可以搞定.但两次的时间是一样的. 代码如下: #include<bits/std ...

  3. JVM指令集(指令码、助记符、功能描述)

    JVM指令集(指令码.助记符.功能描述) 指令码 助记符 功能描述 0x00 nop 无操作 0x01 aconst_null 指令格式:  aconst_null 功能描述:  null进栈. 指令 ...

  4. 编写高质量代码改善C#程序的157个建议——建议133:用camelCasing命名私有字段和局部变量

    建议133:用camelCasing命名私有字段和局部变量 私有变量和局部变量只对本类型负责,它们在命名方式也采用和开放的属性及字段不同的方法.camelCasing很适合这类命名. camelCas ...

  5. 移动距离——第六届蓝桥杯C语言B组(省赛)第八题

    原创  问题描述: 移动距离 X星球居民小区的楼房全是一样的,并且按矩阵样式排列.其楼房的编号为1,2,3...当排满一行时,从下一行相邻的楼往反方向排号.比如:当小区排号宽度为6时,开始情形如下: ...

  6. thinkjs系统服务启动

  7. ASP.NET Web API总结

    1. 跨域 提供Http层的web api时,通常需要考虑跨域问题. 因为浏览器处于安全考虑,默认不允许前端页面向不是自己所在的ip/域名发起请求,因此需要服务器端指明自己允许部分或所有域名进行跨域请 ...

  8. 手把手带你打造一个 Android 热修复框架

    本文来自网易云社区 作者:王晨彦 Application 处理 上面我们已经对所有 class 文件插入了 Hack 的引用,而插入 dex 是在 Application 中,Application ...

  9. WinForm Column cannot be added because its CellType property is null.

    在Winform  DatatGridView 控件中绑定了一个模型的属性,结果在生成窗口时,发生错误,异常信息如下 : Column cannot be added because its Cell ...

  10. Spring boot整合Mongodb

    最近的项目用了Mongodb,网上的用法大多都是七零八落的没有一个统一性,自己大概整理了下,项目中的相关配置就不叙述了,由于spring boot的快捷开发方式,所以spring boot项目中要使用 ...