Is it possible to implement an automatic scrolling functionality in this code snippet?

https://codepen.io/hexagoncircle/pen/jgGxKR?editors=0110

Stumbled upon some interesting code to tinker with and came across this piece. Attempted to search online for solutions, but my grasp on React (or maybe Java?) is close to zero. Tried following guides from and with no luck. Any assistance would be highly appreciated! Pardon any formatting irregularities as I'm new to this.
CSS:

 @import url('https://fonts.googleapis.com/css?family=Playfair+Display:700|IBM+Plex+Sans:500&display=swap');

:root {
  --color-primary: #6B7A8F;
  --color-secondary: #101118;
  --color-accent: #1D1F2F;
  --color-focus: #6D64F7;
  --base-duration: 600ms;
  --base-ease: cubic-bezier(0.25, 0.46, 0.45, 0.84);
}

// =========================
// Global
// =========================
...

JS:

const slideData = [
  {
    index: 0,
    headline: 'New Fashion Apparel',
    button: 'Shop now',
    src: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/225363/fashion.jpg'
  },
  {
    index: 1,
    headline: 'In The Wilderness',
    button: 'Book travel',
    src: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/225363/forest.jpg'
  },
  {
    index: 2,
    headline: 'For Your Current Mood',
    button: 'Listen',
    src: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/225363/guitar.jpg'
  },
  {
    index: 3,
    headline: 'Focus On The Writing',
    button: 'Get Focused',
    src: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/225363/typewriter.jpg'
  }
]

...

Answer №1

It appears that you are working on implementing an auto-scroll feature for your Slides, essentially turning it into an Automatic Slide-Show.

My suggestion for achieving this would involve utilizing Lifecycle Methods and setting up a function to auto-scroll at specified intervals using setInterval.

I have shared the code with exact changes outlined at Line: 130

  // Initiate an interval when the Component is Mounted
  componentDidMount() {
    const interval = setInterval(this.handleNextClick, 5000);
    this.setState({autoSlide: interval});
  }

  // Clear the Interval when the Component is Unmounted
  componentWillUnmount() {
    clearInterval(this.autoSlide);
    this.setState({autoSlide: -1});
  }

Since you mentioned being new to React, you may not be familiar with Life-Cycle Methods. I recommend educating yourself through the following resources:

  1. React Documentation
  2. React LifeCycle Diagramatic Representation

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

Encountering a "403 Forbidden" error upon deployment to the server due to

Situation: I am developing a website using Spring web MVC, JSP, and HTML/JavaScript. One of the features I have implemented is a search function that communicates with imdbapi.org to retrieve movie/TV show information in JSON format via AJAX. The JSON resp ...

Next.js is faced with a frustrating issue where images and videos are failing to display

I've been working on my Next.js 13 project with TypeScript, eslint, and Chakra UI, but I'm facing an issue with images and videos not displaying. Despite trying both the HTML <img> tag and importing Image from Chakra, the problem still per ...

Implementing a Scalable Application with React Redux, Thunk, and Saga

What sets Redux-Saga apart from Redux-Thunk? Can you explain the primary use of redux saga? What exactly is the objective of redux thunk? ...

Guidelines on implementing the map function to fetch data in ReactJS

Currently, I am working on structuring a homepage with the following setup: const Login: React.FC = () => { [ ... ] return ( <IonPage> <IonContent> <IonSlides pager={false} options={slideOpts}> ...

Leveraging async/await within a React functional component

Just getting started with React for a new project and facing challenges incorporating async/await functionality into one of my components. I've created an asynchronous function called fetchKey to retrieve an access key from an API served via AWS API ...

Attempting to set up node-sass through npm

Encountering an error while trying to install node-sass via npm at any version has left me puzzled. I've gone through several troubleshooting steps: updating node-sass to the latest version updating all dependencies and adjusting webpack.config.js a ...

SEO Optimized pagination for pages without modifying the URL

On my website, I utilize pagination to navigate to various event pages. However, search engines are not picking up the conferences on these pages. Take a look at the code snippet below... <a href="javascript:;" class="first" title="First" onclick="getC ...

Assistance required in publishing a website

Just finished coding my first website in HTML using Notepad. Now I'm wondering how to go about publishing it. Does DREAMWEAVER play a role in this process? Do I need it to upload the code to web hosting services or can I do it directly? And if so, how ...

Once more baffled by the nested boxes, this iteration adorned in vibrant hues and trimmed with a striking border

In a previous inquiry, I sought advice on centering one box within another. However, my attempts this time around have led to some peculiar results. I experimented with two different code variations- one involving a background color and the other utilizing ...

Tips on handling various CSS styles for different layouts in ReactJS

Dealing with two different layouts for the Front End and Admin End has presented a challenge for me. I have been including CSS files in the render function for both layouts, but unfortunately, they conflict with each other. For the Front End layout: impo ...

Adding an item to the collection

When I log my cartProducts within the forEach() loop, it successfully stores all the products. However, if I log my cartProducts outside of the loop, it displays an empty array. var cartProducts = []; const cart = await CartModel .fin ...

Navigate through intricate JSON structure

Struggling with a highly complex JSON object, I am trying to list out all the properties and keys exactly as they are. While I have grasped the concept, I am having trouble with the execution. Every time the object contains another object, I need to call ...

Looking for a solution to this problem - I'm interested in creating a circular image with the help of tailwind css

https://i.sstatic.net/4s3Hg.jpg <div className='flex justify-between w-full'> <div className='px-1 w-full'> <img src='https://images.unsplash.com/photo-1566275529824-cca6d008f3da?ixlib=rb-4.0.3& ...

Encountering a 500 internal server error or receiving an error message stating "invalid value for stripe.confirmCardPayment

I'm currently working on implementing a payment component for my React app using Stripe for the first time. Despite following a tutorial closely, I keep encountering an internal server error or receiving an "invalid value for stripe.confirmCardPayment ...

"Encountered an issue while attempting to scrape data from Rotten Tomatoes website

One of my tasks is to extract information from a webpage on Rotten Tomatoes. This is the screenshot of the page https://i.sstatic.net/i3gwp.png Based on the image, it seems that span class= descriptor is the parent class of a class, and div class = info ...

It is not possible to export Next.js pages that utilize getServerSideProps

Recently, I ventured into learning and working with next.js. I built a simple cpanel page that should fetch data every time the page is requested, similar to React's useEffect hook. To achieve this, I utilized getServerSideProps which worked perfectly ...

IFrame displaying blank page instead of report

The following code snippet displays a report within an IFrame: HTML <div id="dialogReport"> <div> <iframe id="reportFrame" style="width: 800px; height: 600px; border: 2px solid black; margin: 10px auto;"> </iframe> </di ...

"How to ensure consistent styling for all buttons, including dynamically created ones, in an application by utilizing the jQuery button widget without the need for repetitive calls to

Hello everyone, I am a newcomer to stack overflow and I have a question to ask. Please excuse any errors in my query. I have searched for an answer but have not been successful in finding one so far. Let's say I have a webpage where I am using the jQ ...

Error caused by live data dynamic update on Highstock chart: Cannot access property 'info' of undefined

Utilizing Laravel, I was able to create Highcharts by consuming data from a Rest API link (Spring app) at . The data is currently displayed statically, but I want to dynamically visualize it on charts. I attempted to follow this example on Fiddle and inte ...

What is the proper way to call document methods, like getElementByID, in a tsx file?

I am currently in the process of converting plain JavaScript files to TypeScript within a React application. However, I am facing an error with document when using methods like document.getElementById("login-username"). Can you guide me on how to referen ...