Discovering the bottom scroll position in an Angular application

I am working on implementing two buttons on an Angular web page that allow the user to quickly scroll to the top and bottom of the page. However, I want to address a scenario where if the user is already at the very top of the page, the "move up" button should be hidden, and vice versa. To achieve this, I came across a function from Google that hides the button when the user has scrolled 1000 pixels from the top.

ts:

window.onscroll = function() {scrollFunction()};
    
        function scrollFunction() {
        
            if (document.body.scrollTop > 1000 || 
                document.documentElement.scrollTop > 1000) {
                document.getElementById("myBtnUp").style.display = "block";
            } else {
                document.getElementById("myBtnUp").style.display = "none";
            }
        
        }
    

HTML:

<button id="myBtnUp">move up</button>
    
        <button id="myBtnDown">move Down</button>
    

Everything is functioning as expected, but I'm struggling to find a way to hide the second button when the user reaches the very bottom of the page. I couldn't locate a control similar to

document.body.scrollBottom > 1000 or
        document.documentElement.scrollBottm > 1000
    

Answer №1

Implement Hostlistener on the window object to monitor scrolling activities.

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

Advantages of passing individual variables instead of the entire object from HTML to JavaScript in AngularJS

When it comes to passing the iterating object from HTML to Javascript, there are two approaches that can be taken. The first approach involves passing the iterating object as a whole, while the second approach only passes the required properties of the obj ...

Utilize the standard error handler in Angular 4

In my Angular4 application, I have set up a custom error handler as follows: @Injectable() export class CustomErrorHandler implements ErrorHandler { handleError(error) { switch (error.type) { case 'custom': doTheThing(); defa ...

Ensure that selecting one checkbox does not automatically select the entire group of checkboxes

Here is the code I'm using to populate a list of checkboxes. <label class="checkbox-inline" ng-repeat="item in vm.ItemList track by item.id"> <input type="checkbox" name="item_{{item.id}}" ng-value="{{item.id}}" ng-model="vm.selectedItem" /& ...

The Angular version update is experiencing issues within the Bash command prompt

https://i.stack.imgur.com/2ic0N.png I'm currently using version 6.0.8 of Angular, but when I try to add Angular/PWA to my project, I encounter an error. The command prompt shows my Angular CLI version as 6.0.8, however, in my bash command it displays ...

Display and conceal table columns dynamically in Vue by utilizing the Vuetify data table functionality

Looking for an example: How to show hide columns of vuetify data table using v-select list I have created something similar, but I'm facing an issue where the table doesn't refresh when changing the header data: https://codepen.io/Meff1/pen/vY ...

``If you're looking to integrate a 360-degree product viewer into your Angular application, here is a

I am in need of showcasing a 360 Product viewer consisting of an array of 36 car images in base64 format. Despite attempting to utilize the angular-three-sixty Package by @mediaman, I was only met with an empty canvas. Does anyone have experience in implem ...

How to extract a specific Observable<T> from an Observable<T[]> array in RxJS

When studying Angular, I created a simulated web service that accomplishes two tasks: It provides an Observable of an array (Observable<T[]>) It offers an item identified by ID as an Observable (Observable<T>) This is the approach I used: e ...

Angular 2 integration for Oauth 2 popup authorization

I am in the process of updating an existing Angular application to utilize Angular 2. One challenge I am facing is opening an OAuth flow in a new pop-up window and then using window.postMessage to send a signal back to the Angular 2 app once the OAuth proc ...

Creating a dynamic selection in Angular without duplicate values

How can I prevent repetition of values when creating a dynamic select based on an object fetched from a database? Below is the HTML code: <router-outlet></router-outlet> <hr> <div class="row"> <div class="col-xs-12"> & ...

Improving Efficiency in Angular 2 for Managing a High Volume of Items

Imagine a scenario where I have created a component that showcases a list of items. export class ListComponent implements OnInit{ public list:any; constructor(private _ls: ListService) {} ngOnInit() { this._ls.listLoad().subscribe((data ...

There is a lack of a service available for AngularFireDatabase

Currently, I am trying to follow a tutorial on creating a chat room application in Angular. Unfortunately, I encountered some issues while setting up AngularFire2. Upon inspecting the package.json file, I noticed that the tutorial is using version 4.0.0-r ...

Is there a way to access a specific argument in yargs using typescript?

The idea behind using yargs is quite appealing. const argv = yargs.options({ env: { alias: 'e', choices: ['dev', 'prod'] as const, demandOption: true, description: 'app environment&apos ...

Error message on Angular 4: "404 - Unable to locate file

Currently, I am working with Angular 4 and attempting to load .csv data. For reference, I have been following this guide: . However, I am facing issues while trying to load the sample.csv file. Despite trying to place the file in src/app, src, or root dire ...

Tips for transferring a boolean parameter through Route Guards in Angular

Protecting the routerLinks based on boolean configurations fetched from a server is crucial. Currently, I have implemented a route guard called canActivate in the ActivateRoutes file. async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnaps ...

What is the best way to retrieve data in my client component without risking exposing my API key to unauthorized users?

To retrieve information, I plan to use pagination in order to specify a particular page number within the API URL and fetch additional data by updating the value of page. The process of fetching data in my server component is as follows: // fetchData.tsx ...

Understanding how to handle prop types in a React application using Typescript

My current task involves using the react-google-maps library to integrate Google Maps API into my project. The documentation specifies a certain way to set up the maps component: const GoogleMapComponent: React.ComponentClass<{}> = compose( with ...

What is the best way to handle installing peer dependencies when using Angular CLI?

Every time I try to update my Angular CLI and NPM, I get stuck in a cycle of errors. After updating, I receive WARN messages instructing me to install peer dependencies (listed below). However, when I try to install these dependencies, more WARN messages a ...

Learn how to trigger an event or API call in Angular 8 when the browser is closed with the help of HostListener

I am facing the challenge of calling a simple websocket closure API when the browser is closed in my project. I attempted to utilize HostListener, but unfortunately it did not work as expected. You can find the code snippet below: https://stackblitz.com/ ...

Tips on eliminating expansion upon button click in header within an Angular application

While utilizing Angular Materials, I encountered a challenge with the mat-expansion component. Every time I click on the buttons within the expansion panel, it closes due to the default behavior of mat-panel. Requirement - The panel should remain expanded ...

When trying to use global.mongoose in Typescript, a type error is being thrown

I'm attempting to incorporate caching into my database connection file in order to streamline the process for my next.js application and avoid repeating the connection step every time I interact with the database. import mongoose from 'mongoose&a ...