Auto Hiding Header on Scroll in Ionic

Поделиться
HTML-код
  • Опубликовано: 21 июл 2017
  • In this coding session, we will build a directive and modify the behavior of Ion-Header component. We will made the header auto-hide as the user scrolls towards the bottom and show up again as the user scrolls toward the top.
    Join Me on FaceBook goo.gl/o2G36O
    WooIonic on CodeCanyon: codecanyon.net/item/wooionic-...
    Learn to build Ionic 3 Apps for WooCommerce. Grab a Coupon Here: goo.gl/uDbuad
    Learn to Build Ionic 3 Apps with Parse Server goo.gl/PWAWny
    Build an eCommerce Mobile App from start to end using Ionic Framework 3 and WooCommerce using HTML, SCSS and TypeScript.
    Ionic 3 Apps for WooCommerce is a course that will help you understand the basics of the latest version of Ionic Framework, v3, and also walk you through, step by step, to build a complete eCommerce application for Android and iOS using your WooCommerce Store as the back-end. Ionic Framework v2 and v3 are similar, so even if you want to learn Ionic 2, you need the same course.
    The eCommerce app that we will build in this course gets the products' information from the WooCommerce store. You do not need to setup any extra databases or servers. All you need is just a WooCommerce store, either locally or on a remote server.
    Don't own a WooCommerce Store yet? You will learn how to setup a WooCommerce store for free on your own computer and then use it to build an eCommerce App. You do not need to buy any tool or software. The course uses all open-sourced technologies.
    You will build an eCommerce app that will allow the user to browse through the product catalog, search products in a particular product category, add product to their cart and then pay for their orders. The customers can pay using the PayPal payment gateway as well. The users will get Push Notifications every time you publish a new product.
  • НаукаНаука

Комментарии • 42

  • @thesamarthagarwal
    @thesamarthagarwal  6 лет назад +3

    GitHub Repo: github.com/samarthagarwal/ScrollingHeader

    • @MegaSyid
      @MegaSyid 5 лет назад +1

      Not working on Ionic 4

  • @PrashantSharma-cu4ip
    @PrashantSharma-cu4ip 6 лет назад

    Thanks Samarth, you are always the best solution to my many project requirements.

  • @CodingWithGhostInCode
    @CodingWithGhostInCode 6 лет назад

    Thanks a lot Samarth, you just saved me Gigs of data bundles. Thumbs Up!

  • @MrYuraseven
    @MrYuraseven Год назад

    Hi, thanks for the tutorial. If I do long scroll and scroll up at some point, shouldn't it immediatly show up? Doesn't work right now.

  • @saajanbajaj641
    @saajanbajaj641 6 лет назад

    Hello Samarth, I want to do same thing using searchbar like when user focus on searchbar then i want to hide the header and on cancel button it will show again just like in iOS. if you have any idea please let me know.

  • @rexzaurusvids3204
    @rexzaurusvids3204 6 лет назад

    me funciono bien, saludos desde Mexico¡¡¡

  • @FullStackDevGreg
    @FullStackDevGreg 4 года назад

    For those have an error with this.header undefined please try this
    This is gonna work:
    ngOnInit(): void {
    this.headerHeight = this.header.clientHeight;
    console.log('in ngOnInit',this.header['_elementRef']['nativeElement'])
    this.renderer.setElementStyle(this.header['_elementRef']['nativeElement'], 'webkitTransition','top 700ms');
    }
    onContentScroll(event:any):void{
    if (event.scrollTop > 56) {
    this.renderer.setElementStyle(this.header['_elementRef']['nativeElement'], 'top','-56px');
    }else{
    this.renderer.setElementStyle(this.header['_elementRef']['nativeElement'], 'top','0px');
    }
    }
    From the log you will notice that it is where the DOM is located

  • @ajithab9353
    @ajithab9353 5 лет назад

    A lag on reached to top after sliding to bottom. Others are good . Keep in touch

  • @rodrigoquintas1313
    @rodrigoquintas1313 5 лет назад

    Work in ionic 4?

  • @NoFaceCoder
    @NoFaceCoder 5 лет назад

    thank you so much

  • @yeshwantkumar1453
    @yeshwantkumar1453 6 лет назад

    Great video.! We can also use deltaY property of event to make it more better, so that user don't have to go to top of content to see header. I also have a quick question, how can we use it in a page that contains ion-slides.? Because it is working fine in a simple page, but not in a page that contains ion-slides. How can we make it work with ion-slides.

    • @thesamarthagarwal
      @thesamarthagarwal  6 лет назад

      I am using it in a page with ion-slides without issues.

    • @CameronPak
      @CameronPak 6 лет назад

      Hey, can you provide more information on deltaY?

  • @alejandrombc
    @alejandrombc 5 лет назад +3

    It works strangely on ios devices. On android is perfect!

    • @MegaSyid
      @MegaSyid 4 года назад

      It's flickering in iOS device because the CSS height is manipulated

  • @pauloluyege7877
    @pauloluyege7877 6 лет назад

    @Samarth Agarwal
    works well in ionic 2 but Having issues with this in ionic 3 ERROR Error: Uncaught (in promise): Error: Template parse errors:
    Can't bind to 'header' since it isn't a known property of 'ion-content'

    • @abhinpai7531
      @abhinpai7531 6 лет назад

      Hey, Even i am facing the same problem, did you find the solution for this problem

    • @SkodaAn
      @SkodaAn 6 лет назад

      (SOLUTION): look at this post stackoverflow.com/a/40407697/6548297 -- and use (ionScroll)="onContentScroll($event)" inside your html file instead of host: {'(ionScroll)': 'onContentScroll($event)'}

    • @arj1411
      @arj1411 6 лет назад

      Hi, could you explain a bit more? I am facing the same issue

    • @eduardoborba6685
      @eduardoborba6685 6 лет назад

      on app.module.ts -> import { HideHeaderDirective } from '../directives/hide-header/hide-header';

  • @EltonWhybrow
    @EltonWhybrow 7 лет назад

    I am using ionic 3 and I wonder if you could help?
    I get WebkitTransition error
    "Runtime Error
    Uncaught (in promise): TypeError: Cannot set property 'webkitTransition' of undefined TypeError: Cannot set property 'webkitTransition' of undefined at EmulatedEncapsulationDomRenderer2.DefaultDomRenderer2.setStyle (localhost:8100/build/vendor.js:34151:29)"
    Thanks
    Elton

    • @thesamarthagarwal
      @thesamarthagarwal  6 лет назад

      Simply means that this.fabToHide is undefined in your case. Make sure your code is in ngOnInit and the directive is defined on ion-content.

  • @khmerangkor538
    @khmerangkor538 6 лет назад

    I have tried this by following your tutorial. It works perfectly . But I have another issue. I have a long list of names and when user scroll all the way to the bottom, how can i make the header reappear in just a few pixels scroll back to the top? I don't want user to scroll all the way back through the list of names in order to see the header again.

    • @chrisbotha4143
      @chrisbotha4143 6 лет назад

      if(event.directionY == "down" && event.deltaY > 112) {
      this.renderer.setElementStyle(this.header, "top", "-" + this.headerHeight + "px");
      this.renderer.setElementStyle(this.scrollContent, "margin-top", "0px");
      } else if(event.directionY == "up" && event.deltaY < -6) {
      this.renderer.setElementStyle(this.header, "top", "0px");
      this.renderer.setElementStyle(this.scrollContent, "margin-top", this.headerHeight + "px");
      }

    • @khmerangkor538
      @khmerangkor538 6 лет назад

      Chris Botha thank you!

  • @thinkagain99
    @thinkagain99 6 лет назад

    HOw to auto show the header if we scroll up without reaching the top?

    • @johangelbaez6043
      @johangelbaez6043 6 лет назад +2

      Instead of using scrollTop use deltaY. Works for me!

    • @NoFaceCoder
      @NoFaceCoder 5 лет назад

      Super it works really awesome. Thank you

  • @SampathLokuge
    @SampathLokuge 6 лет назад +5

    Good content. Thanks. But please turn off the music when you do the teaching. It is real pain and annoying now.

  • @erperejildo
    @erperejildo 6 лет назад

    it works ok but we need to got to top: 0 to display the header again. We should display the header as soon we scroll top a little bit. Also it does a jump when it hides.
    codepen.io/kaililleby/pen/HALnJ

  • @joaomello2761
    @joaomello2761 6 лет назад +2

    In my case get error in ionic 3 v3.20.0, ERROR Error: Uncaught (in promise): Error: Template parse errors: Can't bind to 'header' since it isn't a known property of 'ion-content',
    The solution was to add HideHeaderDirective in the home module
    declarations: [
    HomePage,
    HideHeaderDirective
    ],

  • @mdsarfrazkhan3460
    @mdsarfrazkhan3460 6 лет назад

    Good work,
    But I am facing a problem while scrollContent set to margin-top: 0px OR 56px
    Runtime Error
    Cannot read property 'style' of undefined
    TypeError: Cannot read property 'style' of undefined
    at DefaultDomRenderer2.setStyle (localhost:8100/build/vendor.js:34193:15)
    at DebugRenderer2.setStyle (localhost:8100/build/vendor.js:13787:23)
    at RendererAdapter.setElementStyle (localhost:8100/build/vendor.js:10901:27)
    at HideHeaderDirective.webpackJsonp.261.HideHeaderDirective.onContentScroll (localhost:8100/build/main.js:231:27)
    at Object.eval [as handleEvent] (ng:///AppModule/HomePage.ngfactory.js:120:43)
    at handleEvent (localhost:8100/build/vendor.js:12273:138)
    at callWithDebugContext (localhost:8100/build/vendor.js:13565:42)
    at Object.debugHandleEvent [as handleEvent] (localhost:8100/build/vendor.js:13153:12)
    at dispatchEvent (localhost:8100/build/vendor.js:9173:21)
    at localhost:8100/build/vendor.js:11101:20
    Ionic Framework: 3.6.0
    Ionic App Scripts: 2.1.4
    Angular Core: 4.1.3
    Angular Compiler CLI: 4.1.3
    Node: 8.4.0
    OS Platform: Windows 10
    Navigator Platform: Win32
    User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36

    • @thesamarthagarwal
      @thesamarthagarwal  6 лет назад

      Match your code against the Github Repo.

    • @mdsarfrazkhan3460
      @mdsarfrazkhan3460 6 лет назад

      Thanks Samarth for your Reply but can you provide the link of Github Repo please, "Auto Hiding Header on Scroll in Ionic"

    • @thesamarthagarwal
      @thesamarthagarwal  6 лет назад

      github.com/samarthagarwal/ScrollingHeader

  • @chanlito4896
    @chanlito4896 6 лет назад

    Good job, but I suggest u use bigger fonts for us mobile viewers.