Is there a way to prevent autoplay on swiper only on one slide based on a specific condition?

One of the slides contains a form that opens when a button is clicked within that same slide. However, due to autoplay being enabled, the swiper continues to the next slide. I need to disable autoplay when the user clicks on the form opening button. The form is located at index=1.

import Hero1 from "./Hero1/Hero1";
import Hero2 from "./Hero2/Hero2";
import Hero3 from "./Hero3/Hero3";
import { Swiper, SwiperSlide } from "swiper/react/swiper-react.js";

// Ensure styles are imported directly
import "swiper/swiper.scss"; // core Swiper
import "swiper/modules/navigation/navigation.scss"; // Navigation module
import "swiper/modules/pagination/pagination.scss";
import "swiper/modules/autoplay/autoplay.scss";
import "swiper/modules/effect-fade/effect-fade.scss";

// Import Swiper styles
import "swiper/swiper-bundle.min.css";

import SwiperCore, { EffectFade, Autoplay, Navigation } from "swiper";

import "./Header.css";
// SwiperCore.use([EffectFade, Navigation, Autoplay, Pagination]);
function Carouselgal() {
  const [play, setplay] = useState(true);
  const [duration, setduration] = useState(3000);

  SwiperCore.use([EffectFade, Navigation, Autoplay]);

  return (
    <>
    
      <Swiper
        autoplay={{ delay: duration, disableOnInteraction: false }}
        navigation={true}
        loop={true}
        className="home__carousel"
        effect="fade"
      >
        <SwiperSlide>
          <Hero1 play={setplay} />
        </SwiperSlide>
        <SwiperSlide data-swiper-autoplay="10000">
          <Hero2 />
        </SwiperSlide>
        <SwiperSlide>
          <Hero3 />
        </SwiperSlide>
      </Swiper>
    </>
  );
}

export default Carouselgal;

Answer №1

Simply skip the autoplay settings.

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

Automatically unselect the "initially selected item" once two items have been selected in Material UI

As someone new to web development, I'm struggling with a specific task. Here is the issue at hand: I have three checkboxes. If box1 and then box2 are selected, they should be marked. However, if box3 is then selected, box1 should automatically unchec ...

Ways to showcase the Item's name in the Material-UI Data Grid

Using the DataGrid component from Material UI React to showcase my data. This is how my database looks: https://i.stack.imgur.com/l4au3.png This is the code for my columns const columns = [ { field: 'user_id', headerName: 'User&apos ...

Error: Import statement is not allowed outside a module while running on live server

//this is the Greetings.js file import React from "react"; function DisplayGreetings() { return ( <div><h1>Welcome</h1></div> ) } export default DisplayGreetings //This is the Main.js file import React,{Compone ...

Can a string be transformed into HTTP POST parameters?

Below is a snippet of code where I've utilized the .serialize() method to convert all form inputs into a string, which is then sent to the server: $.ajax({ type: "post", url: wp_urls.ajax_url, data: { action: "submit_form", ...

Designing a MongoDB document structure that includes subdocuments with similar properties

Currently, I am in the process of developing a referral feature and I am relatively new to MongoDB. My main issue lies in figuring out how to construct a document that contains multiple similar subdocuments - specifically, 4 email addresses. The challenge ...

Issue: Package 'cairo' not located on EC2 Bitnami MEAN server

Setting up my MEAN application on a Bitnami server has been quite a challenge. During the installation of dependencies, I encountered an error that I just can't seem to resolve. Despite following the instructions provided in the error message, I am st ...

Implementing a Slide animation in React

I am currently working on a carousel feature that includes two buttons, Next and Previous. When the user clicks on Next, I want the carousel to slide from left to right, and when they click on Previous, it should slide from right to left. One important not ...

Retrieve the visitor's IP address following the submission of an AJAX form

Currently, I am facing an issue with my HTML form and JavaScript method integration. Whenever a visitor submits the form, a JavaScript method is triggered which sends an AJAX request to a PHP file on my server. The problem arises when trying to retrieve ...

Positioning a div at the bottom of the viewport, centered with 2 rows of 6 elements, and adjusting its size to fit the page

I've searched for answers but haven't found anything that works for me. I'm looking to have 2 rows of 6 elements at the bottom of the page and have them stick there as the page scrolls. I tried using a table, which almost worked. .center ...

Accessing state property of a different component in ReactJS: A comprehensive guide

I have a main component that incorporates a menu component. The menu component utilizes a state property to store information about the selected menu item. However, I am now faced with the challenge of retrieving the selected module in the main component. ...

intricate pattern matching tool for Angular

Can someone help me create a regular expression that can validate input in the format "S19/999999/090"? I need the input field to accept this specific type of input where the first character is an uppercase letter from A to Z, followed by two digits from 0 ...

Using Angular components to manipulate the CSS in the DOM

Struggling with dom manipulation in an angular/node.js environment using typescript for my visualcomponent.html The second inline styling works fine, showing the h1 in blue color. However, I run into issues when trying to embed strings within the innerHTM ...

What is the reason for not modifying the filtered and sorted data?

I am currently working on implementing filter options for an item list, but I am facing an issue where the filtering does not work when selecting dropdown options. Array in App.jsx const cameraShowList=[ {id:1,model:"Canon",title:"Canon ...

Counting each item with jQuery and assigning them numbers 02, 03, 04, etc., with the exception of the first item which will display as "Up Next

I'm still learning jQuery and here's the code I've put together after researching on stackoverflow and other platforms: var counter = 1; $('.next-page .nav-item').each(function () { if ($(this, ':gt(0)')) { $(this ...

What factors should you consider when selecting between Bootstrap and MDBootstrap for your class usage?

My CSS skills are not very advanced. I have been using MDBootstrap for most of the styling on my project, but I am not a fan of its table styling. I would prefer to use the table CSS class from regular Bootstrap instead of MDB. I have both dependencies inc ...

Displaying a message indicating no results have been found in the typeahead dropdown using Angular Bootstrap

Is there a way to display a "No Results Found" message in the typeahead search results if no matching data is found? Any suggestions on how to achieve this? See the attached reference screenshot for an example of the message. https://i.sstatic.net/fDpJZ.p ...

The text exceeds the width of the element

Currently, I am facing an issue with displaying notifications where the text exceeds the element width. I am looking for a solution to make the text wrap to the next line if it is too long. https://i.sstatic.net/5NcNs.png To handle notifications, I am ut ...

Having trouble generating a bin executable for my npm package

Referencing: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin I am attempting to generate a "binary" for my npm package. The structure of my package.json is as follows: { "name": "@internal/my-exe", "version": "0.0.0", "type": "commo ...

Clicking on a movie doesn't reveal any details for me

I am encountering an issue where I click on a movie to view its information, but only the details of popular movies are displayed, not the ones I have searched for. Even though the URL indicates that I am viewing the correct movies, no information is shown ...

Continuously visible pop-up during page redirection in Next.js with React

Currently, I am utilizing Next.js for a project that I am actively working on. I am seeking guidance on how to display a popup (potentially based on Alert or Modal) to the user when they are redirected to a specific page. The scenario I am facing involves ...