Require text to display as carousel scrolls by

I am currently using 'Owl Carousel' to showcase content on my website. Underneath the carousel, there is a special text block that I want to update as I scroll through the carousel. Unfortunately, my jQuery skills are not strong enough to make this happen. The text should change depending on which element is at the center of the carousel.

For instance, if element number 1 is in the center, I want the text to display: "Hello, this is the first element". As I scroll to the next element, the previous text should disappear and be replaced by the text associated with the new element.

Does anyone have any ideas on how to achieve this?

// Using Owl Carousel plugin version 2.2.1

$('.projects-carousel').owlCarousel({
    loop:true,
    margin:30,
    nav:true,
    center:true,
    responsive:{
        0:{
            items:1
        },
        1600:{
            items:2,
            stagePadding:75
        }
    }
});
<div class="owl-carousel projects-carousel">
    <div class="projects-Wrapper">
        <div class="projects-img-wrapper">
            <a class="popup-youtube" href="#"><img src="img/projects/1.png" alt="Jey The Dog"></a>
        </div>
    </div>
    <div class="projects-Wrapper">
        <div class="projects-img-wrapper">
        <a class="popup-youtube" href="#"><img src="img/projects/2.png" alt="Jey The Cat"></a>
        </div>
    </div>
</div>



<div class="text-block">
    <!-- Need help connecting the carousel elements with their corresponding text here -->
</div>

Answer №1

Include the following content into the slider:

<div class="owl-carousel projects-carousel">
    <div class="projects-Wrapper">
        <div class="projects-img-wrapper">
            <a class="popup-youtube" href="#"><img src="img/projects/1.png" alt="Jey The Dog"></a>
        </div>
        <p>Enter your desired text here</p>
    </div>
    <div class="projects-Wrapper">
        <div class="projects-img-wrapper">
        <a class="popup-youtube" href="#"><img src="img/projects/2.png" alt="Jey The Cat"></a>
        </div>
        <p>Enter your desired text here</p>
    </div>
</div>

Next, you can use CSS to adjust their positions:

.projects-Wrapper {
  position: relative;
}

.projects-Wrapper p {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 25%;
}

Answer №2

I have managed to find a solution to my own query, which may be beneficial to others in the future. Here is how I tackled it:

('.projects-carousel').owlCarousel({
    loop:true,
    margin:30,
    nav:true,
    center:true,
    mouseDrag:false,
    touchDrag:false,
    navText: ["<i class='fa fa-long-arrow-left'></i>","<i class='fa fa-long-arrow-right'></i>"],
    items: 3
  });
  
// This code block places the content of the central carousel element onto the page by default.
$('.projects-h3 h3').html($('.center .project-content h3').html());
$('.projects-text p').html($('.center .project-content p').html());

/* Identifies the central element in the PROJECTS carousel (using the '.center' class which is part of the owl carousel plugin) each time the navigation button is clicked and updates the text content accordingly. */
$(".projects-carousel .owl-nav").click(function(){
  $('.projects-h3 h3').html($('.center .project-content h3').html());
  $('.projects-text p').html($('.center .project-content p').html());
});

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 access the current Google account signed in on an Android device using jQuery and Cordova?

Is it possible to retrieve the currently logged in Google account on Android devices using jQuery and Cordova? $(function(){ $('#LoginForm').submit(function(){ var loginData = $ ("#LoginForm").serialize(); ...

Connecting one property of a JavaScript object to another property within the same JavaScript object

I am working with a JavaScript Object and I want to use the map() function to match the Id with another id in the same JavaScript Object. Here is the schema for my JavaScript Object: var items = [ { BossId: "03", DateOfBirth: "1966-09-27T00:00:0 ...

Modal not opening when activated from Foundation Foundation

I am encountering difficulty in triggering the Reveal modal, and I cannot figure out the issue. Initially, I suspected a JavaScript conflict. To troubleshoot, I stripped down the site to its essentials: some CSS, some JS, and some HTML. However, even afte ...

Asynchronously parsing CSV files in NodeJs using the `await` keyword within the `on('data')`

I have a specific code snippet that is designed to read lines from a .csv file one by one and then store each processed row into a database const csv = require('csv-parse') const errors = [] csv.parse(content, {}) .on('data', async ...

Tips for swapping text with an image or icon during mobile scaling

As a newcomer to this field, I am facing challenges in finding specific answers. My current objective is to convert text labels into images when the viewport shrinks to mobile sizes. The complexity arises from the fact that I am employing Leaflet, a JavaSc ...

Recursive React components. String iteration enhancement

In my React app, I am trying to create a string hierarchy from an object. The object structure is like this: { name: 'name1', parent:{ name: 'name2', parent:{ name: 'name3', parent: null }}} My plan is to use a state variable ...

Discovering an unfamiliar HTML element: the mysterious <spinner> tag - its origin and purpose remain a puzzle

UPDATE: As I eliminate possibilities, it appears that this is related to the https://github.com/mpalourdio/ng-http-loader module which is injected by another dependency. What's interesting is that this module uses the tag <ng-http-loader>, not & ...

Choosing specific elements with Selenium using OR/AND operations in Python

I am encountering an issue while working with Selenium using Python. Here is a preliminary example of my code snippet. <body> <button info="content1" aria-label="1">"Click 1"</button> <button info ...

Tips for organizing inputs neatly within a fieldset

Why are my text input fields longer than select tags? How can I make inputs have the same width as selects? form fieldset { width: 50%; margin: auto; border: 3px solid grey; padding: 10px; } form fieldset legend { font-size: 20px; ...

Using a color as a substitute for a background image on mobile devices

Is there a way to create a fallback in my CSS for changing the background image to a color when viewed on a mobile browser once the pixels reach the max-width? In the snippet below, the media query "only screen and (max-width: 600px)" works if the top bod ...

Karma-coverage examines the test coverage of JavaScript files rather than TypeScript files within Angular 2

I am facing an issue with checking test coverage in TypeScript files using Istanbul and setting test thresholds via karma-coverage. The problem arises because karma-coverage checks test coverage in JavaScript files instead of TypeScript, which leads to mis ...

My website has a navbar button that is not directing to the intended section of the screen

I have created this HTML code for my Navbar buttons: <button class="navbar-toggle" data-toggle = "collapse" data-target=".navHeaderCollapse"> <span class="icon-bar"></span> <span class="icon-bar">< ...

Store Dark Mode preferences in the browser's local storage using React and Material-UI

Is there a way to save the dark mode setting in localStorage? Can this approach be used for storing it? Any suggestions on how to achieve this would be appreciated. Thanks, cheers! function App() { const [darkState, setDarkState] = useState("&qu ...

What is the best way to handle the rows that have been checked in the table?

Imagine you have the given table structure: <table> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> </tr> </thead> <tbody> <t ...

What is the best way to access a value within a JSON object in a React render method?

Overview I am currently working on creating a blog using React and JSON data. Upon checking this.state.blogs, I am getting the output of: [object Object],[object Object],[object Object]. I have attempted to use the .map function but I am not sure how to ...

Determining the duration of a button long press in React in seconds

Is there a way to track and display the number of seconds a button is being held down for? For example: "click and hold, starts counting 1, 2, 3, 4, 5, then resets to 0 when released" I have made progress with this functionality, and it works correctly i ...

Fixing the Issue with React Redux Store Adding Items to Cart and Redux Logger Troubleshooting

Issue with Redux-logger not displaying actions when the add to cart button is clicked. store.js import { legacy_createStore as createStore, applyMiddleware } from "redux"; // The middleware function in between action firing and root reducer all ...

Sorting a MongoDB collection based on the count from another collection

My question involves two collections: collection A and collection B. Collection B has a field "A_id" that corresponds to the _id from Collection A (creating a relationship between them). Details for Collection A: { _id, name } Information for Collec ...

Is there a way to create a dropdown menu that transforms into a burger icon on smaller screens, while still housing all of my navigation items within it?

I'm currently working on a segment of my header that includes a navbar with 3 links, as well as a dropdown menu listing additional functionalities. Here is the current code I have: <div class="col-md-4 pt-4"> <nav class="navbar ...

Customizing Bootstrap Navigation: Creating Space Between Menu Items

I've configured my Bootstrap navigation with a dropdown toggle for "Coverage". I'm looking to decrease the spacing between each list item (li) under this dropdown. What CSS setting should I use to achieve this? Interestingly, when I apply float: ...