How to navigate through individual items in a Bootstrap carousel

I am facing an issue with my WP theme where the bootstrap carousel is moving by four items at a time instead of one. I want to achieve a continuous loop where it moves one item at a time infinitely. I attempted to implement this solution but only the first item was visible.

Below is a snippet of my current code:

 <div class="carousel slide" data-ride="carousel" id="partneri-carousel">                          
        <div class="carousel-inner">

        <div class="item active">
            <div class="col-3 column text-center">
             <div class="logo">
                 <img src="http://demo.kybernaut.cz/dgsimona/wp-content/uploads/2015/02/cvicny_partner2.png">
                 </div>
                 <div class="popisek">Simona je nkjnaskndkjsan bjhdbasjhbdjhba snhjqbsjwqb sbjqwbsq dbjudwzgzd</div>
                 <div><a href="http://www.kybernaut.cz" target="_blank">www.kybernaut.cz</a></div>                                  
            </div>
             .... (Remaining HTML code)
        
    </div>;

        <!-- Carousel Buttons Next/Prev -->
        <a data-slide="prev" href="#quote-carousel" class="left carousel-control"><img src="http://demo.kybernaut.cz/dgsimona/wp-content/themes/sb/images/arr_simple_left.png" alt="arr_simple_left"></a>
        <a data-slide="next" href="#quote-carousel" class="right carousel-control"><img src="http://demo.kybernaut.cz/dgsimona/wp-content/themes/sb/images/arr_simple_right.png" alt="arr_simple_right"></a>
      </div>                          
    </div>

Here is the jQuery script I am using:

<script>
$(document).ready(function() {
  $('#partneri-carousel').carousel({
    pause: "hover",
    interval: 4000,
  });
});</script>

The desired behavior should be like this: (numbers represent the "partner box", "=>" denotes the movement of carousel, for example, having six partner boxes) 1 2 3 4 => 2 3 4 5 => 3 4 5 6 => 4 5 6 1 => 5 6 1 2 => infinite loop

Thank you in advance for any assistance!

Answer №1

Items within a Bootstrap carousel are identified by the class "item", causing the first four items to appear as one cohesive element.

Here is an example of a single item:

<div class="item active">
  <div class="col-3 column text-center">
   <div class="logo">
     <img src="http://demo.kybernaut.cz/dgsimona/wp-content/uploads/2015/02/cvicny_partner2.png">
     </div>
     <div class="popisek">Simona je nkjnaskndkjsan bjhdbasjhbdjhba snhjqbsjwqb sbjqwbsq dbjudwzgzd</div>
     <div><a href="http://www.kybernaut.cz" target="_blank">www.kybernaut.cz</a></div>
  </div>
</div>

The existing code does not correctly handle controls for the carousel.

I have reorganized your markup in this fiddle, aiming to meet your requirements: http://jsfiddle.net/davidcw/k1jnj15b/

Best of luck!

Edit: Setting Variable Number of Items Dynamically in WordPress

Apologies for the confusion. To achieve your goal, you can manage opening and closing divs based on whether the number of images aligns with your target (e.g., 4). Use a counter and the following approach within your .carousel-inner div:

<?php

    $i = 1;
    // initiate the opening of the div before the loop
    echo "<div id='item-$i' class='item'><ul class='carousel-thumbnails'>";

    $rowcount = count( get_field('carousel_images')); // total image count - consider adjusting counting method.

        while( has_sub_field('carousel_images') ){

             /*===========================================================*/
             $slidenumber = 4; // SET NUMBER OF SLIDES HERE
             /*===========================================================*/
             $thumb_id = get_sub_field('image');
             $thumbsize = "thumbnail"; // (thumbnail, medium, large, full or custom size)
             $thumbimage = wp_get_attachment_image_src( $thumb_id, $thumbsize );

             ?>
              <li>
                 <img src="<?php echo $thumbimage[0]; ?>" />
              </li>
              <?php

         // close current div and open new div if multiple of $slidenumber
         $itemNumber = ($i / $slidenumber) + 1;

         if( $i % $slidenumber == 0 && $i < $rowcount) {

           echo "</ul></div><div id='item-$itemNumber' class='item'><ul class='carousel-thumbnails'>";

            }

        $i++;

        };

    //ensure final div is closed
    echo "</ul></div>";

    ?>

Structure of the markup:

<div class="row">
  <div class="col-md-12">
    <div class="carousel slide" id="thumb-carousel">
      <div class="carousel-inner">
        <!--
        Insert PHP logic from above here
        -->
      </div><!-- /.carousel-inner -->
      <!-- Carousel navigation -->
      <a class="left carousel-control" href="#thumb-carousel" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span></a>
      <a class="right carousel-control" href="#thumb-carousel" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span></a>
    </div>
  </div>
</div>

Additionally, apply jQuery to assign the active class to the initial carousel item to start the carousel:

(function( $ ) {'use strict';
  $(function() {
    // Set the first thumbnail item as active
    $("#thumb-carousel .item:first").addClass("active");
  });
})( jQuery );

To ensure proper display of images in the ul, include CSS rules like these:

ul.carousel-thumbnails {
  font-size: 0;
  width: 100%;
  padding-left: 0;
  margin-bottom: 0;
  height: 78px;
  overflow: hidden;
}
.carousel-thumbnails li {
  display: inline-block;
  margin-left: 20px;
}

Answer №2

Have you experimented with the moveSlides setting? Although I am not familiar with the specific script you are utilizing, it seems like the code is designed to handle that functionality.

(I apologize for being unable to provide a more detailed response in the form of a comment; my reputation does not allow me to do so at this time.)

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

Truncating text with ellipsis in CSS when wrapping on a nested div structure

Here is a 3-tier nested div tree structure with the outer node having a maximum width where I want the ellipsis wrapping to occur. I've almost achieved the desired result, but the issue arises when the inner nodes are not trimmed to accommodate as mu ...

if statement based on the conditions set in the CSS

I've been struggling with an issue for a whole day now, and I just can't seem to solve it. I have a few keydown functions that change the background image under certain conditions when the 'active' class is not present. Here's an e ...

Enhancing the functionality of a bootstrap button with the addition of an

My goal is to have a button that opens a URL in a new tab. I've managed to achieve this using window.location.href, but it doesn't open the URL in a new tab. The code I'm working with is written in jQuery and Javascript, and it's part ...

Executing 'npm start' to launch an HTML file along with a CSS stylesheet - A step-by-step guide

As a newcomer to the world of coding, I've found that asking questions on platforms like Stack Overflow enables me to connect with fellow developers. I usually code using VS Code and rely on the "live server" extension to quickly test my code. Howeve ...

What is the best way to incorporate a large amount of HTML into a webpage using jQuery?

Currently, I am developing a comment script that utilizes PHP and jQuery. After my jQuery sends data to the PHP backend script and receives a successful response, I need it to display the results returned by the backend script. Although everything is fun ...

Grab the code snippet from JSFiddle

I apologize for the seemingly simple question, but I have been struggling with it. I tried looking at similar questions, but I couldn't find a solution. Despite copying the code from http://jsfiddle.net/sB49B/21/, I can't seem to get it to work ...

What is the process for deleting an animation using JavaScript, and how can the background color be altered?

Two issues are currently troubling me. First off, I am facing a challenge with an animation feature that I need to modify within the "popup" class for a gallery section on a website. Currently, when users load the page, a square image and background start ...

Is there a way to incorporate an 'ended' feature into the .animate() function?

I'm currently working on a jQuery statement where I want to activate pointer events once the button animation is finished. However, I'm unsure how to incorporate an ended or complete function. Any suggestions on how to approach this? $('#ce ...

I am encountering an issue with opening a dropdown select option upon clicking in C# while using Selenium

I am encountering an issue while attempting to open the Register page from my account. The UI developer utilized Bootstrap code, and Bootstrap developers have included a JS function on click. However, when I execute this code, an error is thrown: "OpenQA.S ...

The width of the container is exceeded by the drop-down menu during hover

My responsive drop-down menu is causing issues when the media query activates and I hover over the links, causing the width of the drop-down menu to extend beyond the container. <!-- Navigation Menu --> <div class="container"> ...

Send variable to jQuery from a div element

I'm struggling with adjusting the height and width of a dialog box using a jquery function. I want to pass a parameter from within the DIV, but I haven't been successful in finding a solution. Any suggestions would be greatly appreciated. $.fx.s ...

Ways to modify the appearance of the Sign up page on Moodle

I'm a newcomer to the world of Moodle, currently using version 2.9. I've created a unique design for my Signup page using HTML5 and CSS. How do I go about integrating this custom page? While I understand how to change the default Login page by m ...

choosing and identifying the iframes for YouTube videos

I have a webpage that showcases images of YouTube videos, allowing users to choose from them. This is how I am presenting them: <ul> <li> <div class="youtubeMediaContainer"> <img src="video_preview_image1.jpg"& ...

Iterating through two classes in a Javascript loop

Hello, I'm facing a small obstacle that I'm hoping to overcome using JavaScript/jquery. Essentially, I have multiple div classes and I want to create a loop that adds a class to specific divs without manually assigning an id to each one. The goal ...

Problem with Bootstrap multiselect: it only opens the first time, and stops working after an ajax call

I am having trouble using Bootstrap multiselect with jQuery ajax. When I run the ajax code, the multiselect button stops working properly. To see the issue in action, click here: and look at the last multiselect dropdown. Here is the ajax code snippet: ...

Implementing Auto-complete Functionality with Tagify in C# ASP.Net using jQuery

I'm currently utilizing Tagify, a tool that utilizes jQuery Autocomplete, references : <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquer ...

When using Next.js, the global.css file is not loaded until a manual page refresh is performed. Additionally, the styles.js

The current situation is that styling is being applied in two places: global.css and index.js using styled-components. Challenge When the local server is started or restarted, and a manual page refresh is done, all styles are correctly applied. Any style ...

linking ng-style through live html

I am encountering an issue with dynamic data stored in the database. When trying to apply a style to a div element retrieved from the server response, I am facing difficulties with implementing it using ng-style. If the data is static, everything works fi ...

Can a child element be shown even when the parent element is hidden?

Is it possible to have a hidden parent and a visible child using CSS or jQuery? I'm attempting to make a child element visible on certain pages even if the parent is hidden. var bodyClass = jQuery('body').attr('class'); //ale ...

Creating image filters using an object in jQuery

I am faced with a challenge where I have multiple image tags nested within a div that has the class google-image-layout. Each image is equipped with various data attributes, including: data-anger="0" data-disgust="0" data-facedetected="0" data-fear="0" da ...