Angular4 allows for the creation of a div that can horizontally scroll

Below is the HTML code I am working with:

<div class="card-deck" fxLayout.xs="row" style="overflow: scroll; height:100%">
    <md-card style="width:10rem" *ngFor="let make of filteredMakes" (click)="goToModels(make.niceName)"
             class="page-card mat-card">
      <img md-card-image=""  src="assets/img/gallery/brands/256/{{make.name}}.png" class="mat-card-image" />
      <md-card-subtitle  class="mat-card-title text-center">{{ make.name }}</md-card-subtitle>
    </md-card>
</div>

Here is how it appears on mobile devices:

https://i.sstatic.net/3t7Cs.png

I am interested in implementing an animation that automatically scrolls horizontally to the last manufacturer, but stops when a user interacts with it.

To break it down:

  1. User visits page and sees the automatic scroll
  2. User realizes it's a scrolling div and begins to manually scroll using their finger
  3. Auto-Scrolling is disabled at this point (until the user resets the page state)

My challenges are:

  1. How can I set up automatic scrolling using javascript? (preferably with control over the scroll speed, like 50px/sec)
  2. How do I detect user interactions with the "card-deck" div (such as touch gestures, sliding, etc.)

Answer №1

1) To implement auto-scrolling, you can utilize a JavaScript function like setInterval to periodically change the position of your div.

2) Another option is to use the @HostListener annotation (Check out the Angular documentation) to monitor user interactions and stop the auto-scrolling by calling clearInterval on the setInterval function when a click event occurs.

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

What is the best way to import a typescript file using a provided string?

I have a directory filled with JSON schemas, all coded in TypeScript. My goal is to import them collectively while preserving the typing, instead of having to write out numerous import statements. These schemas are utilized for validating JSON data being ...

List out the decorators

One query is bothering me - I am attempting to create my own version of Injectable and I need to determine if a specific decorator exists in my Class. Is there a way to list all decorators of a class? Let's take the example below. All I want to know i ...

What is the process of invoking a JavaScript function from Selenium?

How can I trigger a JavaScript function from Selenium WebDriver when using Firefox? Whenever I am logged into my website, I typically utilize this command in Firebug's Command Editor to launch a file upload application: infoPanel.applicationManager. ...

Leveraging the power of javascript to include content before and after

I am looking to understand how I can insert an HTML element before and after certain elements. For example, let's say we have the following code in a real file: <ul class="abcd" id="abcd></ul> How can I display it like this using JavaScr ...

Guide on altering the cell's background hue depending on its value through javascript

I'm dealing with a table that has 3 columns: field1 is a Category field2 and field3 contain Measures (specifically integers 1, 2, 3, 4, and 5). Is there a way to use Javascript to conditionally format the background color of cells in the table hol ...

Duplicate user scrolling input within a specified div container

I am attempting to recreate a horizontal scrolling effect on a div element that mirrors the input scroll. When the user scrolls along the input, I want the div element to scroll in sync. The issue I am encountering is specific to Chrome, where the input b ...

Incorporate a unique identifier for dynamic elements

Is there a way to give generated divs the same name so I can markup them easily? $.getJSON("data/reviews.json", function(data){ for(var i=0; i<data.length; i++) { var review = sym.createChildSymbol("Template", "content"); review.$("title").html ...

Guidelines for attaining seamless motion animation utilizing devicemotion rotationRate information

I am utilizing the rotationRate data obtained from the devicemotion eventListener to manipulate a three.js scene by tilting. The scene does respond to the data accurately in terms of angle adjustments, but it produces an unsmooth motion effect. Is there a ...

React: The issue with async and await not functioning as expected when using fetch

I am working with an API on a Node server that returns JSON data like this: {"result":[{"ProductID":1,"ProductName":"iPhone10","ProductDescription":"Latest smartphone from Apple","ProductQuan ...

Dealing with errors in node.js

Node.js asynchronous functions typically have a callback, with some like fs.writeFile passing an err argument. fs.writeFile('message.txt', 'Hello Node', function (err) { if (err) throw err; console.log('It\'s saved!& ...

FireFox is unresponsive to OPTIONS requests

I have a webpage that is accessed through HTTP. The client-side code is making AJAX requests for authorization to the same domain, but using HTTPS, which causes CORS issues. When using FireFox, the request looks like this: // domains and cookies are chang ...

Testing attributes and props with React Testing Library

Currently, I am in the process of developing a React application using TypeScript. For creating components, I rely on material-ui and for unit testing, I make use of react-testing-library. Specifically, I am working on designing a wrapper for the Grid com ...

Can the conventional HTML context menu be swapped out for a link context menu instead?

Currently, I am working on developing a custom linkbox component that is similar to the one found on this page: Here is an example of the code: export const Linkbox = ({}) => { const linkRef = useRef(null); return ( // eslint-disable-next-l ...

Retrieve the file name of the webpage from the URL bar

Is there a way to retrieve the page name from the address bar using jquery or javascript instead of PHP? I am working on an HTML website and would prefer not to use PHP for this specific task. For example, if the address is www.mywebsite.com/hello.htm, ho ...

Special effects for the images动画效果。

Is there a way to add animation effects to images in the about section using this code: <div id="about" class="row section bgimg3"> <div class="col-sm-8"> <h2 style="color:black;">Want to Know More About me?</h2> ...

Send binary information using Prototype Ajax request

Currently, I am utilizing Prototype to send a POST request, and within the postdata are numerous fields. One of these fields contains binary data from a file, such as an Excel spreadsheet chosen by the user for upload. To retrieve the contents of the file ...

Error in Angular 7: Can't assign type 'void[]' to type

I am trying to populate a document object in Angular 7 typescript but encountering an error. The error message states: "Type 'void[]' is not assignable to type 'IDocumentDetails[]' export interface IDocumentUpload { fileDropEntry: ...

How can we efficiently generate ReactJS Router for Links and seamlessly display a unique page for each Link?

Currently, I have an array of objects named titleUrl, which contains titles and URLs retrieved from an API. To display these as links on the sidebar, I am utilizing a custom component called MenuLink. The links are generated by iterating over the keys in t ...

Recognition of the ng-click function in Ionic buttons can occasionally be unreliable

I am experiencing an issue with my Ionic app that wraps a web-app using Angular. Within the app, there are buttons coded like this: <ion-view view-title="Orders"> <ion-content scroll="true" overflow-scroll="true"> <div class="row"> ...

The Clarity Design side menu becomes unscrollable when the content is too long for the view

Currently, I am facing an issue with the sidenav where the navigation links go beyond the view and I am unable to scroll to see the "hidden" links unless I zoom out. My frontend framework is Angular 5 and this is how I organized the components: <nav c ...