Code Monkey home page Code Monkey logo

ion-header-scroll-opacity's Introduction

npm npm npm

ion-header-scroll-opacity

Now compatible with Ionic 4 ๐ŸŽ‰.

Change header background opacity on content scroll.

install

npm i ion-header-scroll-opacity --save

If you are using Ionic 3 install ion-header-scroll-opacity@^1.0.0 and use to the ion-header-scroll-opacit#ionic-3 branch for reference.

Import directive

Import the IonHeaderScrollOpacityModule into the your page module

import { IonHeaderScrollOpacityModule } from "ion-header-scroll-opacity";

@NgModule({
  [...]
  imports: [IonHeaderScrollOpacityModule],
  [...]
})
export class HomePageModule {}

Usage

Put the header-scroll-opacity directive on the ion-header element.

Directive Input

Input Description Default value
ionContentRef ion-content reference none
scrollAmount Amount of pixel to be scrolled in order end the opacity transition 88
isTransparent If true the header background starts with opacity=0 true
<ion-header scrollOpacity [ionContentRef]="mycontent">
  <ion-toolbar color="primary">
    <ion-title>
      Do scroll
    </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content #mycontent [scrollEvents]="true">
  ...long scrolling content...
</ion-content>

Remember to set [scrollEvents]="true" on the ion-content component otherwise the directive will not work.

Tip

Add the fullscreen attribute to the ion-content element and add some css style to make a good effect

.scroll-content {
  padding-top: 0px !important;
}

Demo

Demo

Contribute

Any pull-request and issues are wellcome

ion-header-scroll-opacity's People

Contributors

dependabot[bot] avatar toriphes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ion-header-scroll-opacity's Issues

Property not known?

Hi, thanks for doing this directive, its exactly what I was looking for!

I did bump into something weird that an hour of Google didn't solve.

Template parse errors:
Can't bind to 'scrollArea' since it isn't a known property of 'ion-header'.

My html:

<ion-header class="home-common" color="sdbredfg"  header-scroll-opacity [scrollArea]="mycontent">
    <ion-navbar>
        <button ion-button menuToggle>
            <ion-icon class="icon-menu" name="menu" color="sdbredfg"></ion-icon>
        </button>
        <ion-title color="sdbredfg">Preparation</ion-title>
    </ion-navbar>
</ion-header>
<ion-content class="page-guide home-common" no-padding #mycontent fullscreen>

So it seems to be objecting to having added [scrollArea] as a property, which makes sense..

There was another article (https://medium.com/@gregor.srdic/ionic3-hidding-header-on-footer-on-content-scroll-15ab95b05dc5) that in the comments had similar issues.

ps, in your docu you say to use it in the app.module.ts declarations, though that errors, and logically should be as an import...

@input ionContentRef shoud be a valid instance of IonContent

My header is separate module like below.

<ion-header class="ion-no-border" scrollOpacity [ionContentRef]="mycontent"> <ion-toolbar lines="none" [class.item-background-color]="showToolbar"> <div class="logo" slot="start"> <div class="big-text"> <ion-icon src="/assets/logo.svg"></ion-icon> </div> </div> <ion-buttons slot="end" class=" notificatoin_button"> <ion-back-button [text]="Back" [hidden]="!edited" defaultHref="/home"></ion-back-button> <ion-button [routerLink]="['/notifications']"> <ion-icon class="badge" name="notifications-circle-outline"> </ion-icon> <ion-badge class="badge-one" color="light">{{notification_cnt}}</ion-badge> </ion-button> </ion-buttons> </ion-toolbar> </ion-header>

And above header module call in all pages like below.
<app-header></app-header>

Now I am trying to use this it gives below error.

core.js:4197 ERROR Error: Uncaught (in promise): Error: @input ionContentRef shoud be a valid instance of IonContent
Error: @input ionContentRef shoud be a valid instance of IonContent
at IonHeaderScrollOpacityDirective. (header-scroll-opacity.directive.ts:80:13)
at Generator.next ()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.