Tips for automatically hiding a button when the ion-content is being scrolled and displaying it again once scrolling has stopped

I have implemented a scroll function event in my HTML file using the following code:

<ion-content (ionScroll)="scrollFunction($event)">
    <ion-card *ngFor="let product of products" no-padding>
    <ion-item class="bigclass">
     <ion-thumbnail item-height="100px" item-start>
       <img-loader *ngIf="product.images" src="{{product.images[0].src}}" useImg></img-loader>
     </ion-thumbnail>
    </ion-card>
    <ion-infinite-scroll (ionInfinite)="loadMoreProducts($event)">
     <ion-infinite-scroll-content></ion-infinite-scroll-content>
    </ion-infinite-scroll> 
</ion-content>
<ion-footer>
    <button class="proceed" *ngIf="isShown" ion-button full (click)="proceedPayment()">Proceed</button>
</ion-footer>    

In my .ts file, I am trying to hide and show a button based on scrolling behavior. The current implementation hides the "Proceed" button when scrolling down, but I want it to also be hidden when scrolling up. It should only become visible when the scroll stops within the ion-content.

public isShown:boolean=false;
constructor(public navCtrl:NavController){
    this.WooCommerce.getAsync('products?
      consumer_key=ck&consumer_secret=cs').then((result) => {
      console.log(JSON.parse(result.toJSON().body));
      this.products = JSON.parse(result.toJSON().body);
      console.log(this.products);
      this.products.forEach(product => { product.quantity = 1, 
      product.disabled=false;});
      return JSON.parse(result.toJSON().body);         
    }, (err) => {
      console.log(err)  
    })
}

public scrollFunction = (event: any) => {
    let dimensions = this.content.getContentDimensions(); 
    let bottomPosition = dimensions.contentHeight + dimensions.scrollTop; 
    let screenSize = dimensions.scrollHeight;
    this.isShown = screenSize - bottomPosition <= 10 ? true : false;
}

Answer №1

To make use of the ion-content element, you can attach the below method:

  • ionScrollStart
  • ionScrollEnd

    <ion-content (ionScrollStart)="scrollStart($event)" (ionScrollEnd)="scrollStart($event)

This will trigger the event and update the variable isShown.

  scrollStart(event) {
     this.isShown = false;
   }

  scrollStop(event) {
     this.isShown = true;
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Verify login availability using Javascript auto-check

For quite some time now, I've been grappling with a significant issue that has been consuming my attention. I am determined to implement an auto-check login availability feature in the registration form of my website. My goal is for it to verify the ...

Using jQuery to create a dynamic fullscreen background image that responds to mouse movement

I am currently working on creating a dynamic full screen background that responds to the movement of the mouse. The idea is that as you move the mouse around, the background image will shift accordingly. For instance, if you were to move the mouse to the ...

JQuery / Javascript - Mouse Position Erroneously Detected

I'm currently working on developing a drawing application where users can freely draw by moving their mouse over a canvas. My goal is to create a pixel at the precise location where the user drags their mouse. However, I've encountered an issue ...

Handling a change event for a mat-datepicker in Angular 7 can be tricky, especially when its value is tied to an optional input parameter. Let's dive into how to

I've recently started working with angular development and encountered a challenge with a mat-datepicker. The value of the datepicker is connected to filterDate using [(ngModel)] as an @Input() parameter. I have implemented a handleChange event that e ...

Avoid placing the label within a form-inline in Bootstrap to maintain proper formatting and alignment

I am working on a form where I have two fields inline within a form-inline div. I am looking to move the labels of these fields above them rather than next to them. How can I achieve this without affecting the layout of the fields? Here is a CodePen link ...

Navigating through a multistep form in AngularJS using UI Router and arrow keys for seamless movement

Is there a way to navigate to the next or previous form step using arrow keys in AngularJS UI Router? The code provided below is currently allowing navigation with previous and next buttons. .config(function($stateProvider, $urlRouterProvider) { $stat ...

Is there a way to make jQuery Validate display errors within the form elements rather than outside of them?

Given the jQuery Validate basic example provided in the link below, what method can be used to display error messages within form elements whenever feasible (excluding checkboxes)? http://docs.jquery.com/Plugins/validation#source ...

What is the best way to vertically align the second row in a carousel using Tailwind CSS?

Currently, I am working on developing an up-and-down carousel with Tailwind CSS. However, I am encountering a challenge in aligning the elements in the second row of my grid. My main objective is to have these elements centered vertically within the grid. ...

Utilize the 'document / redirect' API within an express controller function

Here is how I have an API call using document / redirect: This call is made within HTML Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmln ...

Having Trouble Choosing Options From Dropdown Menu Using Index in Selenium with Java

I am familiar with how to choose an element from a dropdown using the selectByIndex method. However, when attempting to use selectByIndex (select.selectByIndex(index)) on the HTML snippet below: <select id="destinationAllocationId" name="destinationAll ...

Struggling with color styling within link_to tags in Rails 4 - having trouble getting inline styling to show up correctly

<%= link_to "Sign In", new_user_session_path, :method => :get, style: "color:white" %> <h3>Read More - <%= link_to 'Article', action: :articles, style: "color: purple" %></h3> <%= link_to 'Click to Read More Abo ...

Issue with background image positioning in IE 7 while scrolling

I am struggling with creating nested divs where the middle one has a fixed background image that remains static while the rest of the content scrolls. My solution works in Firefox, Chrome, and Opera but I'm encountering issues in IE7. Despite knowing ...

Modifying the colors of my navigation links is not within my control

How can I modify my CSS to change the color of the navigation links to white? Below is the code snippet: <div class="col-sm-12"> <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header" ...

How can I set a minimum height for a table on my website?

Is there a way to make a table that is at least 50px in size, but can still enlarge if there is a lot of text inside? I'm not sure if this even makes sense, but any help would be appreciated. Thank you! ...

Click anywhere outside the sidemenu to close it

I want the menu to behave like the side menu on Medium. When the side menu is open and the user clicks outside of #sidebar-wrapper, the side menu should close. Currently, I have to click the toggle X to close the menu. html <a id="menu-toggle" href="# ...

Interacting with HTML5 canvas using object events

How can I assign an event handler to an element created on the HTML5 Canvas without having to manually track specific coordinates? ...

The submit button is getting disrupted by the background image being set

Implement the following CSS code to set a background image on a single-page app (Angular). .page::before { content: ''; position: absolute; background-size: cover; width: 100%; height: 100%; background-image: url("../../assets/weird. ...

Sort div elements based on checkbox filters

I have a set of checkboxes that I want to use for filtering purposes. <div class="filter"> <div class="checkbox"> <label><input type="checkbox" rel="canada"/>Canada</label> </div> <div class="chec ...

Will my JavaScript function be triggered when the page is resized while printing?

I have a simple HTML layout where I am using the TextFill jQuery library to automatically adjust the text size based on available space. Everything looks good on screen, but when printed, it seems like the page is resized and the JavaScript needs to be re ...

Tips for creating a sticky bootstrap column that remains in place as you scroll

I am looking to design a FAQ page similar to Twitter's FAQ. The goal is to have the left column remain fixed in its position while allowing users to scroll through the content. Here is what I have attempted so far, but it is not functioning as expect ...