How can I integrate a timer into an Angular carousel feature?

I have put together a carousel based on a tutorial I found on a website. Check out the HTML code for my carousel below:

<div class="row carousel" (mouseover)="mouseCheck()">
                    <!-- For the prev control button -->
                    <button class="control" style="left: 30px;" (click)="prevButton()">
                        <span class="arrow" style="transform: rotate(45deg);"></span>
                    </button>

                    <div class="row car-align">

                        <div *ngFor="let i of currentSlide;" style="width: 184px;" class="card CardBtw">
                            <div @carouselAnimation>
                               <!-- SOME CODE IN HERE -->     
                            </div>
                        </div>

                    </div>

                    <!-- For the control buttons -->
                    <button class="control" style="right: 30px;" (click)="nextButton()">
                        <span class="arrow" style="transform: rotate(225deg);"></span>
                    </button>                    
                </div>

After successfully implementing an animation, I now aim to make the carousel cycle every 10 seconds when the mouse is not hovering over it. If the user places their mouse on the carousel, I want the countdown to reset and start from the beginning. I've created a function called "mouseCheck()" to monitor if the mouse is on the carousel but I'm struggling with setting up the 10-second cycle. Any suggestions on how to achieve this?

EDIT:

As requested, here are the relevant codes. My mouseover function currently only logs a message when the mouse is detected (I haven't fully implemented it as I'm having trouble tracking time). When using the next and previous buttons, I hide and reveal the appropriate vector. Here's the TypeScript function for the next button:

//Start from the first vector
  currentSlide = this.laptopSlide[0];

  nextButton() {
      //If the currentSlide is 0
      if(this.currentSlide == this.laptopSlide[0])
        this.currentSlide = this.laptopSlide[1]
      //If currentSlide is 1
      else if(this.currentSlide == this.laptopSlide[1])
        this.currentSlide = this.laptopSlide[2]
      //If current slide is 2
      else if(this.currentSlide == this.laptopSlide[2])
        this.currentSlide = this.laptopSlide[0];
    }

Answer №1

One way to add a setTimeout function within the mouseCheck() function is by using the following code:

  mouseCheck() {
   if (condiction1 or click == true){
     on.click() => {
         "Provide a function condition"
      }
    }else {
     setTimeOut({
       console.log("Modify content dynamically in my component's TypeScript code")
     }, 2000)
  }

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

Tips for locking the button in the navigation bar while scrolling

I noticed that when I have 6 fields in my navbar, with 5 of them being links and one as a dropdown, the scrolling of the page causes all fields to remain fixed except for the dropdown field.Check out this image description for reference https://i.stack.im ...

Using injected services within static methods may seem tricky at first, but once you

I am exploring the integration of angularjs and typescript in my project. Currently, I am working on creating an Orm factory using typescript but have encountered some challenges. The structure of my factory class is as follows: class OrmModel implements ...

What is the best way to convert dates in Angular's DatePipe using moment.js?

My current package versions are as follows: "@angular/cdk": "^11.2.13", "@ngx-translate/core": "^13.0.0", "@angular/material-moment-adapter": "^12.2.9", "moment": "^2.29.1", &q ...

Oxygen-style with a sleek, shadow-free frame

Currently, I'm utilizing the qtoxygen style and I am curious if anyone knows how to remove the shadow frame on QPlainTextEdit. Even after attempting to customize the CSS with { border: none }, the shadow continues to be displayed. ...

Ways to simulate a function that is a part of an internal object

Is there a way to mock a method from an object within my UnderTest class? When the Update method is triggered by an event from a child component, I need to mock the service.saveNewElement(data) method in order to test data in the then() block. <script ...

capturing webpage content with javascript for use in a screenshot

Is there a way to capture a screenshot of a webpage using JavaScript and utilize the canvas tag for this purpose? I attempted to use the html2canvas plugin in the past, but found it lacking in power. I would like to achieve this without relying on extern ...

Error: The use of import statement is not allowed outside a module in JavaScript due to a Syntax

I'm just beginning my journey with React, starting from scratch without setting up all the necessary dependencies. Initially, I used CDNs in my html file but now I want to learn how to import React and ReactDOM into my local setup and also link CSS fi ...

Retrieving text content from an HTML element with Jsoup for web page manipulation

My task involves extracting text content from a specific HTML element <span class="adr" style="float: none !important;"> <span class="street-address" style="float: none !important;">18, Jawaharlal Nehru Road, </span> ...

Modifying CSS to ensure compatibility with various browsers

I am curious if it is possible to modify some CSS when viewed in a different browser. For instance, I have this CSS for a flexbox div: .wdFlex { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit- ...

When using Angular 2 formControl, manually changing the value may not be detected by the form

Having a simple form (as shown below), I am encountering an issue: Manually entering input value causes form.controls['myValue'].value to change If #myInput value is changed programmatically, the form completely ignores that change What could ...

Having trouble retrieving text from an HTML form in Node.js using express, as the req.body object is coming up

Having trouble extracting text from an HTML form to build a basic text to speech functionality. Despite using an express server, the req.body is consistently empty when attempting to fetch the text. I've experimented with body-parser and adjusted the ...

How can I handle a queue in Angular and rxjs by removing elements efficiently?

I'm facing a challenging issue with my code that I need help explaining. The problem lies in the fact that a function is frequently called, which returns an observable, but this function takes some time to complete. The function send() is what gets c ...

A guide to storing data within the client's HTML: Tips and tricks for optimal storage placement

As I develop my website, I am using a technique where I store a simplified version of the web page within the HTML itself. This allows me to send efficient Ajax requests back to the server, as it can analyze what the client's page looks like and send ...

Changing pricing on pricing table with a click

Looking to implement a price changing button that functions similar to the one found at this LINK: If anyone knows of any JavaScript or other solution, please provide me with some guidance. Thank you in advance. ...

Having trouble with jQuery on my webpage

Looking for assistance with a technical issue I'm facing... I am currently working with AngularJS and have integrated jQuery into my project. However, I've encountered an issue where the jQuery code is not functioning as expected on the HTML pag ...

What is the process for incorporating a CSS class into a preexisting Woocommerce/Wordpress widget?

Looking for a way to add additional classes to the Woocommerce Product Categories Widget without tampering with the original source code or creating a replacement widget? The widget_display_callback seems like the way to go, but the available documentation ...

Troubleshooting the issue of process.nextTick not being recognized in Calgolia places.js

After successfully implementing Algolia's places.js in my Angular 7 project using NPM, I encountered an issue. I have integrated a form where one of the fields should be an input. <form [formGroup]="myForm"> <pre style="color: white; b ...

Angular 5 Web-Based EPUB Reader

Just getting started with Angular 5 and I'm looking to display an epub file on a page without resorting to iframes. Any suggestions on how to achieve this? ...

Testing TypeScript using Jasmine and Chutzpah within Visual Studio 2015

I am new to unit testing in AngularJS with TypeScript. I have been using jasmine and chutzpah for unit testing, but I encountered an error "ReferenceError: Can't find variable: angular". My test file looks like this: //File:test.ts ///<chutzpah_r ...

Registering a function for chart.js plugins that manipulates external data

Is there a way to pass external data to the chart.plugins.register function? I'm struggling because I can't access the necessary context: Chart.plugins.register( { beforeDraw: function (chart) { //implementation } }); I attempted using ...