# Hide Header and Footer on Scrolling with Animation

**URL:** <https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545>\
**Category:** showcase\
**Created:** [October 3, 2018, 9:35am UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545 "2018-10-03T09:35:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![hirenkorat3](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/hirenkorat3/32/128872_2.png) [@hirenkorat3](https://forum.ionicframework.com/u/hirenkorat3)\
**Post date:** [October 3, 2018, 9:35am UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/1 "2018-10-03T09:35:29Z")

</div>

Demo:  
 ![infinity](https://global.discourse-cdn.com/ionicframework/original/3X/f/f/ffeabddf250377a56e3bbbc7341629f7cfcc481e.gif)

generate directive

`ionic g directive HideHeader`

and copy below code in hide-header.ts file

```auto
import { Directive, Input, ElementRef, Renderer } from '@angular/core';

@Directive({
  selector: '[hide-header]', // Attribute selector
  host: {
    '(ionScroll)': 'onContentScroll($event)'
  }
})

export class HideHeaderDirective {
  @Input("header") header: HTMLElement;
  @Input("footer") footer: HTMLElement;
  constructor(public element: ElementRef, public renderer: Renderer) {
    console.log('Hello HideHeaderDirective Directive');
  }
  ngOnInit() {
    this.renderer.setElementStyle(this.header, 'webkitTransition', 'top 700ms');
    this.renderer.setElementStyle(this.footer, 'webkitTransition', 'bottom 700ms');
  }
  onContentScroll(event) {
    if (event.directionY == "down") {
      this.renderer.setElementStyle(this.header, 'top', '-56px');
      this.renderer.setElementStyle(this.footer, 'bottom', '-56px');
    }
    else {
      this.renderer.setElementStyle(this.header, 'top', '0px');
      this.renderer.setElementStyle(this.footer, 'bottom', '0px');
    }
  }
}

```

and simply add directive to any header and footer in page

```auto
<ion-header #header>
  <ion-navbar>
    <ion-title>
      Ionic Header
    </ion-title>
  </ion-navbar>
</ion-header>
<ion-content fullscreen hide-header [header]="header" [footer]="footer">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eum nam totam recusandae, iusto consequuntur quibusdam
    aliquid voluptate, placeat qui explicabo optio facilis similique doloribus aperiam animi voluptas, unde repellat
    sint?</p>
</ion-content>
<ion-footer #footer>
  <ion-navbar>
    <ion-title>
      Ionic Footer
    </ion-title>
  </ion-navbar>
</ion-footer>

```

reference from : [https://github.com/samarthagarwal/ScrollingHeader](https://github.com/samarthagarwal/ScrollingHeader)

---

<div class="post-metadata">

**Author:** ![hirenkorat3](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/hirenkorat3/32/128872_2.png) [@hirenkorat3](https://forum.ionicframework.com/u/hirenkorat3)\
**Post date:** [October 3, 2018, 9:37am UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/2 "2018-10-03T09:37:19Z")

</div>

please share your thought regarding animation improvement or alternate way for it.  
thanks

---

<div class="post-metadata">

**Author:** ![Kyrax80](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@Kyrax80](https://forum.ionicframework.com/u/Kyrax80)\
**Post date:** [October 3, 2018, 9:44am UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/3 "2018-10-03T09:44:34Z")

</div>

Very cool, the animation looks nice and smooth

---

<div class="post-metadata">

**Author:** ![NarendraGumma](https://avatars.discourse-cdn.com/v4/letter/n/7bcc69/32.png) [@NarendraGumma](https://forum.ionicframework.com/u/NarendraGumma)\
**Post date:** [February 15, 2019, 4:37pm UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/4 "2019-02-15T16:37:37Z")

</div>

> [@hirenkorat3](#):
>
> [header]=“header”

How can i do it for sub header?

---

<div class="post-metadata">

**Author:** ![amard](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@amard](https://forum.ionicframework.com/u/amard)\
**Post date:** [April 3, 2019, 9:20am UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/5 "2019-04-03T09:20:26Z")

</div>

I am getting the following error, on the ngInit function. Need some help, anyone?

ERROR TypeError: Cannot set property ‘webkitTransition’ of undefined  
at EmulatedEncapsulationDomRenderer2.push…/node\_modules/@angular/platform-browser/fesm5/platform-browser.js.DefaultDomRenderer2.setStyle (vendor.js:66832)  
at DebugRenderer2.push…/node\_modules/@angular/core/fesm5/core.js.DebugRenderer2.setStyle (vendor.js:58175)  
at RendererAdapter.push…/node\_modules/@angular/core/fesm5/core.js.RendererAdapter.setElementStyle (vendor.js:55711)  
at HideHeaderDirective.push…/src/app/directives/hideheader/hide-header.directive.ts.HideHeaderDirective.ngOnInit (explore-explore-module.js:29)  
at checkAndUpdateDirectiveInline (vendor.js:55940)  
at checkAndUpdateNodeInline (vendor.js:57204)  
at checkAndUpdateNode (vendor.js:57166)  
at debugCheckAndUpdateNode (vendor.js:57800)  
at debugCheckDirectivesFn (vendor.js:57760)  
at Object.eval [as updateDirectives] (ExplorePage.html:24)

---

<div class="post-metadata">

**Author:** ![hirenkorat3](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/hirenkorat3/32/128872_2.png) [@hirenkorat3](https://forum.ionicframework.com/u/hirenkorat3)\
**Post date:** [April 4, 2019, 6:31am UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/6 "2019-04-04T06:31:42Z")

</div>

perhaps this error occurs because of slow html rendering and binding component process. somehow ngoninit() not able to get HTML element of header so i suggest you to check basic value validation for header like if(this.header) then call setstyle() or you can try settimeout() method.

---

<div class="post-metadata">

**Author:** ![amard](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@amard](https://forum.ionicframework.com/u/amard)\
**Post date:** [April 4, 2019, 7:23am UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/7 "2019-04-04T07:23:14Z")

</div>

The setTimeOut didn’t fix it. I’ve described my error in detail, please check this [post](https://forum.ionicframework.com/t/receiving-ionheader-instead-of-htmlelement/160749)

---

<div class="post-metadata">

**Author:** ![NikunjKakadiya](https://avatars.discourse-cdn.com/v4/letter/n/b2d939/32.png) [@NikunjKakadiya](https://forum.ionicframework.com/u/NikunjKakadiya)\
**Post date:** [February 25, 2020, 5:23pm UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/8 "2020-02-25T17:23:09Z")

</div>

Very cooooool, the animation is smooth, superb. thank you thank you so much

---

<div class="post-metadata">

**Author:** ![Thesurya9](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/thesurya9/32/117460_2.png) [@Thesurya9](https://forum.ionicframework.com/u/Thesurya9)\
**Post date:** [July 28, 2020, 7:31am UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/9 "2020-07-28T07:31:37Z")

</div>

Getting same issue … did you find the solution ?

---

<div class="post-metadata">

**Author:** ![hunterdougj](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hunterdougj](https://forum.ionicframework.com/u/hunterdougj)\
**Post date:** [September 30, 2020, 7:06pm UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/11 "2020-09-30T19:06:37Z")

</div>

Has anybody had success running this with Ionic 5 and Angular 10? Granted I’m very new at this, but I can’t get it to work despite following the excellent tutorial. I receive: Msg: Can’t bind to ‘header’ since it isn’t a known property of ‘ion-content’. I don’t think it’s even getting to the Directive because I don’t get the console message from console.log(‘Hello HideHeaderDirective Directive’);

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [September 30, 2020, 8:02pm UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/12 "2020-09-30T20:02:33Z")

</div>

> [@hunterdougj](#):
>
> Has anybody had success running this with Ionic 5 and Angular 10?

No, and they won’t. In fact, it won’t work with any Angular version past 8.x, as it relies on `Renderer`, which was deprecated in v4 and removed in v9.

---

<div class="post-metadata">

**Author:** ![hunterdougj](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hunterdougj](https://forum.ionicframework.com/u/hunterdougj)\
**Post date:** [September 30, 2020, 10:11pm UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/13 "2020-09-30T22:11:42Z")

</div>

Thanks for the update. I did notice that renderer was replaced with renderer2. I was hoping the new renderer2 using setStyle vs renderer’s setElementStyle would do the trick…nope!. Bummer!!

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 8:54pm UTC](https://forum.ionicframework.com/t/hide-header-and-footer-on-scrolling-with-animation/143545/14 "2021-07-19T20:54:04Z")

</div>

Closed on July 19, 2021, 8:54pm UTC


