Effortlessly glide through entire pages using the mouse wheel for seamless scrolling

I provide a seamless full-page scrolling experience using the mouse wheel.

However, the scrollIntoView function does not seem to function within the @HostListener('wheel', ['$event']).

Here is a snippet from app.component.html file:

<div #page *ngFor="let page of [0,1,2,3,4]" [class]="'vh-100 p-3 bg-' + (page + 1)">
  <h3 class="text-white">Page {{page + 1}}</h3>
  <div class="page-content">
    <h3>Lorem Ipsum</h3>
    <p>beatae esse velit laudantium nam eligendi possimus</p>
  </div>
</div>

<div class="nav">
  <button #prev class="btn btn-sm btn-light me-1" (click)="clickPrev()">prev</button>
  <button #next class="btn btn-sm btn-light" (click)="clickNext()">next</button>
</div>

From app.component.ts file:

  // Code logic and functionality here...

Link to Stackblitz for reference

An alternative approach that involves JavaScript and works with document.addEventListener('wheel', (event: WheelEvent) => {})

Another example with working functionality

Any insights on how to make ScrollIntoView work within the @HostListener('wheel', ['$event'])?

Answer №1

The @HostListener functionality is operating as expected. The culprit behind the awkward scrolling behavior is actually the CSS styling.

  • Firstly, wrap both the button and content within a parent div set to 100vh height.

  • Secondly, ensure that the content's position is relative to its original placement.

Explore this solution further on StackBlitz

<div class="vh-100 overflow-hidden">
  <div #page *ngFor="let page of [0,1,2,3,4]" [class]="'vh-100 p-3 position-relative bg-' + (page + 1)">
    ...
  </div>

  <div class="nav">
    ...
  </div>
</div>

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

Cultural adaptation in Angular

I have successfully created an Angular project with internationalization capabilities. However, I am now looking to implement it by culture, such as es-AR or en-NZ. Below are my configurations for Spanish and English in the angular.js file: "build": { ...

How to retrieve an array stored within a JSON object

I am trying to access a specific array within an object from a JSON file. Here is the snippet of the data I'm dealing with: best-sellers": [ { "title": "Chuteira Nike HyperVenomX Proximo II Society", "price": 499.90, "installmen ...

Displaying a single http response in Angular

Having trouble displaying data from a single JSON response using Angular. I've set up a class for the data in interndata.model.ts export class Interndata { humidity: number; temperature: number; constructor(humidity:number, temperature:number) { ...

issue with uploading files in angular 7

Currently, I am facing an issue with Angular 7 where the input type "file" is not working as expected. However, in Angular 6, everything works fine. When submitting the input file type data in Angular 6, I receive a field list like this: https://i.sstat ...

My goal is to create a comprehensive collection of stories showcasing all Material UI components in React

Looking for a way to efficiently import all MUI components stories into my storybook. Is there a tool or repository available that can automate the generation of these stories, or perhaps has pre-written stories for all MUI components? I attempted to cre ...

The map component does not render when the agm-map is placed within the component

Objective I am attempting to encapsulate an <agm-map> within my custom <app-map> component, but it is not appearing in the HTML output. https://i.sstatic.net/7rXeE.png The agm (angular google maps) library is properly configured and the map ...

NX - A comprehensive UI library featuring Storybook integration and individually exported components

As I delve into the world of Nx with Angular (fairly new to both), I am on a quest to create a component library that serves two main purposes: Capable of running Storybook Allowing components to be imported individually, rather than having to drag in the ...

Can you please explain the significance of classes <T> and <U> in Angular 2?

After diving into the Angular 2 TypeScript documentation, I have come across these two classes frequently. Can someone provide a detailed explanation of what they are? One example code snippet from the QueryList API documentation showcases: class QueryLi ...

No declaration file was found for the module named 'vue2-timepicker'

Overview I integrated the vue2-timepicker plugin into my Typescript/Nuxt.js application. However, I encountered an issue with importing vue2-timepicker. import timepicker from 'vue2-timepicker' Could not find a declaration file for module &apos ...

Reassigning Key Names and Types Based on Conditions

How can I modify object key names and properties in a way that allows existing keys and properties to remain the same or be modified (remapped)? My current approach does not properly handle mixed cases: export const FUNC_ENDING_HINT = "$func" as const; ty ...

Securing routes and layouts in the MEAN Stack framework

I am currently utilizing the MEAN Stack framework and have created 3 different layouts. I am looking to secure each layout route to prevent unauthorized access. const routes: Routes = [ { path: '', redirectTo: '/dashboard', ...

I'm searching for TypeScript interfaces that can be used to define OpenAPI Json. Where can I

If you're looking to implement the OpenApi specifications for your project, there are a variety of fields and values that need to be set. For a detailed look at these specifications, you can refer to the documentation here. In an effort to streamline ...

agm-circle has such a high drag sensitivity in angular 4

I have implemented an agm-circle in an agm-map within Angular 4. Everything is working as expected, however, I am experiencing an issue with the speed at which the circle moves when dragged. Is there a way to slow down this movement? Below is my code sni ...

Ways to display or conceal information depending on the dropdown choice

In my Angular project, I am dealing with a dropdown menu that is followed by some data displayed in a div element. component.html <select class="form-control" id="power" required> <option value="" disabled selected ...

The ongoing ESLint conundrum: Balancing between "Unused variable" and "Unknown type" errors when utilizing imports for type annotations

I've encountered a linting issue and I need some guidance on how to resolve it. Here's the scenario - when running $ yarn lint -v yarn run v1.22.4 $ eslint . -v v6.8.0 With plugins vue and @typescript-eslint, I have the following code in a .ts ...

Output the initial value and subsequently disregard any values emitted during a specified time interval

Check out my code snippet: app.component.ts notifier$ = new BehaviorSubject<any>({}); notify() { this.notifier$.next({}); } app.component.html <div (scroll)="notify()"></div> <child-component [inp]="notifier$ | async" /> ...

Using Angular 6 shortcodes in HTML

Is there a way to save an element in HTML as an alias for repeated use in Angular 6 without using *ngIf directive? For instance, consider the following code snippet: <dumb-comp [name]="(someObservable | async).name" [role]="(someObservable | a ...

What is the best way to define the type of an object in TypeScript when passing it to a function

I am currently working on a function that accepts an object of keys with values that have specific types. The type for one field is determined by the type of another field in the same object. Here is the code: // Consider this Alpha type and echo function. ...

What is the reason behind the triggering of actions by ngrx entity selectors?

I'm currently in the process of learning NgRx, but I'm struggling to comprehend why entity selectors would trigger actions. Despite my efforts to find an explanation, I have come up short. It's possible that I may be missing some fundamental ...

Prohibit communication by any means

Let's take a look at the following function overloads: function f(key: undefined); function f(key: string | undefined, value: object | undefined); I want to allow calls with a single explicit undefined argument f(undefined), but require two argument ...