What is the best way to include distinct text beneath each box within this slider or carousel?

Is there a way to add new text at the bottom of each box in this code?

Visit CodePen

I specifically want the new text to show underneath the boxes, not inside them. Each box should have different text associated with it. When you navigate using the left or right arrows, the new text should be displayed along with the corresponding box. Thank you for your help!

<!-- JavaScript functions -->
function shiftLeft() {
    // function logic...
}

function shiftRight() {
    // function logic...
}
<!-- CSS Styles -->
// CSS styles go here...
<head>
    <title>3d-carousel</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
    <div class="container">
        <div class="button" onclick="shiftLeft()"><img src="left_arrow.png" alt=""></div>
        <div class="cards-wrapper">
            <ul class="cards__container">
                <li class="box" style="background-color:red">box 1</li>
                <li class="box">box 2</li>
                <li class="box">box 3</li>
                <li class="box">box 4</li>
                <li class="box">box 5</li>
                <li class="box box--hide">box 6</li>
                <li class="box box--hide">box 7</li>
            </ul>
            <div class="card__text-content">
                <h3 class="card__title">The Famous Five</h3>
                <div class="card__summary">The Famous Five is a series of children's adventure novels written by English author Enid Blyton. The first book, Five on a Treasure Island, was published in 1942.</div>
            </div>
        </div>
        <div class="button" onclick="shiftRight()"><img src="right_arrow.png" alt=""></div>
    </div>
    <script src='js/index.js'></script>
</body>

Answer №1

To tackle this issue, one can adopt various strategies like utilizing jQuery data binding, Vue.js, React.js. Nevertheless, if a straightforward route via vanilla JavaScript is your preference, take note of these instructions:

  1. Allocate a distinctive ID to each block, such as box1, box2, boxn, and beyond.
  2. Every block must have a corresponding card__text-content identified by IDs like databox1, databox2, and so on.
  3. Show or conceal the right card__text-content in accordance with the centrally positioned block.

Make sure to visit the accompanying source code snippet for implementation details and view the CSS and HTML setup for context.

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

Exploring JSON data with multiple nested layers of iteration

I'm currently working on a project that involves parsing through a JSON file with a complex structure. I've been attempting to extract a link to an image within the JSON data, but my current approach is resulting in an error. Below you'll fi ...

Instructions for sending React form information to a database.json file using axios on a local server

I'm having trouble figuring out how to transfer the input data from my form to my JSON file on my localhost. The form in HTML collects a name, title, and content. The objective is to utilize the form to generate a new article, send that form data to t ...

Creating movement in three distinct divisions

I am seeking a way to have three divs flying in upon click. The first DIV is positioned at the top, followed by one on the left and one on the right (both being below the top one). I wish for them to fly in from their respective directions - the top div fr ...

Can javascript be used to swap out the folder in my URL?

I have been searching for solutions on how to change the language of my website using jQuery, but so far I have not found anything that works for me. Let's take my website as an example: www.domain.com I have separate folders for different languages. ...

Creating a tree-like design with the spry accordion換stepping up your spr

I want to style my accordion in a way that it resembles a tree structure. How can I achieve this using CSS? For example: + should be displayed when the accordion tab is closed, and - when the accordion is open. <div class="Accordion" id="systemAccordi ...

Activating the change event in jQuery: A step-by-step guide

Within my ASP.NET page, I have included a UserControl that contains a RadioButtonList. Whenever an item in the RadioButtonList is changed, I need to trigger the following jQuery function: $('#rdlUser').change(function (e) { alert("change fun ...

Eliminate the outline of the pager row in an asp.net grid view

Within my grid view, I have applied a bottom border to all cells. However, this border is also appearing on the pager row, which is not desired. To address this issue, I attempted to use jQuery to remove the border, but it seems that my selector is incorre ...

Differences in the way websites scroll on Chrome compared to Safari and Firefox

Currently, I am in the process of developing a rendering system for my application that extracts objects from a collection and processes them through JavaScript templates to generate additional children as the user scrolls through the page. The system is d ...

What is the best approach to generate and organize 100 random numbers in a program, ensuring they are sorted in ascending order from 1 to 100?

I have successfully implemented the sorting and printout functionality of the program. However, I am now facing a challenge in generating 100 random numbers between 1 and 100, sorting them. I have created an array to store the generated numbers, and I ha ...

Exiting shell sessions may involve NPM, Supervisor, and Nohup

I'm currently using Node LTS and I have a script that needs to run continuously. Even after disconnecting from SSH, I want it to keep running. I recently came across a node package called supervisor which is supposed to restart the process if it crash ...

Struggling to store the results of multiple fetch API calls in an array for future access beyond the function

fetching data from multiple APIs and storing it in an array has been a challenge. While attempting to set the data using useState, only one piece of data successfully makes it into the array. Even after trying Promise.all method, the same issue persists al ...

Dynamically alter the class of the menu on the master page

Can anyone provide guidance on updating the CSS Class name of a menu located in the Master page from a Child Page? I aim to switch the class to "active" whenever any child form of the menu is open. Are there any C# or JavaScript solutions for this scenar ...

The error message in angular.js line 13294 indicates a problem with an unknown provider called cityResourceProvider, which is required by cityResource and cityListCtrl

I'm having my first experience with angularJS and trying to use services and factories to create a web api REST call. I encountered this error message even before making the call: angular.js:13294 Error: [$injector:unpr] Unknown provider: cityResour ...

Getting the data-id of a div within a jQuery dialog box - a step-by-step guide

I am working with jQuery dialogs that contain dynamic divs. I want to trigger a specific function when the jQuery dialog opens. To do this, I need to retrieve the data-id of the div. The names of the divs are generated dynamically. Once I have the data-id, ...

Clicking on the parent div with a Jquery onclick event does not trigger when the child image is clicked

I'm running into an issue with a simple code containing an image within a div Oddly enough, clicking on the div itself (even with padding) triggers the function, but clicking directly on the image does not. $(".parent0").click(function() { conso ...

Requests in Node.js may unexpectedly stall and remain unresolved until the server is restarted

I've encountered a strange and seemingly sporadic issue with our web application that I can't seem to resolve through debugging. The app runs smoothly for varying durations, ranging from 10 minutes to 6 hours, but then all of a sudden, any remote ...

The identifier variable fails to function as a reference when I attempt to utilize it

var lightcount = 0; $("#addlight").click(function(){ var domElement = $('<div id="L' + lightcount +'" class="col-md-3 col-sm-6 text-center"><div class="rumbox"></div><button id="onoff" type="button" c ...

Gathering Servlet details from non-form elements

I am currently in the process of developing an application that is capable of parsing JSON strings. At this stage, I am able to input a JSON string using Java, write it to an HTML document, and then have a JavaScript program read and parse it before ultima ...

Dynamic text input and selection menu with AJAX (PHP and JavaScript)

As a student who is new to Javascript and PHP, I am trying to create a login page for my website that can verify user input in the database using AJAX. For example, when a user enters their username and password, the system should automatically check if t ...

Switching Text in ReactJS from V to X: A Tutorial

I have been utilizing a Switch component from react-switch in my project. import Switch from 'react-switch'; render() { return <Switch onChange={this.onChangeStatus} onClick={this.onChangeStatus} c ...