Display a single item from the Bootstrap carousel on mobile devices

Seeking help with my Bootstrap Carousel - displaying 2 items on Desktop but wanting to show one item at a time on Mobile. Any solutions?

Visit this link for more info

HTML Code:

<div class="container">
  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner" role="listbox>

    <!-- Items shown here -->

    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>

Javascript:

$(document).ready(function(){
     $("#myCarousel").carousel();
});

Looking to make the Carousel design mobile responsive like in the attached image: https://i.sstatic.net/RqCz1.jpg

Answer №1

$(document).ready(function(){
  $("#myCarousel").carousel();
    if ( $(window).width() < 640 ) {
       $('.col-sm-6').unwrap().addClass('item');
       $('.col-sm-6:first').addClass('active');
    }
});

If your mobile breakpoint is set at 640, this code will adjust the layout accordingly. Take a look at unwrap(), which removes an element's parent without affecting its content.

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

Implementing event listeners with Angular UI-Router

Currently, I am working with Angular 1.4.5 and Angular Ui Router. I am facing an issue where I am trying to utilize addEventListener to execute a function when a text field is blurred. The challenge I am encountering is that during the load state, the elem ...

Implementing a Dynamic Navigation Feature using PHP in a Standalone File

I am currently working on creating a dynamic PHP navigation system that should highlight the active tab, but I'm facing challenges with making the active tab part function properly. While there are simpler methods available, they all involve incorpora ...

Navigating through JSON arrays can be achieved by utilizing iteration techniques

I'm having trouble with a script and can't figure out how to make it display in the designated div. It may have something to do with how I'm handling the response. In Chrome devtools, the response looks like this: { "[\"record one& ...

What exactly is the function of registerServiceWorker in React JS?

Just starting out with React and I have a question about the function of registerServiceWorker() in this code snippet: import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import registerServi ...

Encountering issues when using array.map with null entries in a react application

Struggling to iterate over the location array and map it? Despite several attempts, handling the null object within the array seems challenging. What am I missing here? While using a for loop resolves the issue, the map function is proving to be a roadbloc ...

The request for the URL (https://deno.land/std/encoding/csv.ts) could not be sent due to an operating system error with code 100

Encountering an issue with importing the stdlib files from deno.land to the local cache when running mod.ts. Error: error sending request for url (): error trying to connect: tcp connect error: An attempt was made to access a socket in a way forbidden by ...

Sass Alert: The mixin called roboto-family is missing from the stylesheet. Trace: Problem detected in src/pages/forms/forms.scss at

Greetings, I am diving into the world of Ionic for the first time. Recently, I embarked on a new project in Ionic and decided to integrate a theme. To do so, I copied an .html file, an .scss file, and also created a .ts file. Forms.html <!DOCTYPE html ...

Tips for assigning a Custom Formik Component's value to the Formik value

I'm currently integrating Formik into my form alongside Google Places auto-complete feature. My goal is to display the places auto-complete functionality as a custom component within the Formik field. form.js <Formik initialValues={location:" ...

PHP and JS with Jquery often face challenges when trying to work together due to their conflicting array structures

This is a perplexing issue that has me stumped. I retrieved an array of workers from a MySQL database using json_encode and then copied it to two other arrays for future operations. var workers = <?php echo json_encode($tablica_pracownikow); ?>; va ...

By clicking the button, you can add an item to select2

Utilizing the select2 tag style in my Drupal YAML form allows users to easily locate and add various items. These items come with both images and titles on the same page, accompanied by a button next to each image. My goal is to enable users to click the b ...

Issues with jagged borders in three.js while working with gltf documents

Seeking assistance for resolving an issue with a bug. https://i.sstatic.net/F1fov.png The problem is seen in the gltf import of a "sheep-like" object, exported by blockbench. Adjusting the scale does not solve the bugged edges that persist no matter what ...

JavaScript's `indexOf` function can sometimes return false when it should actually return true

I'm having trouble detecting if a specific text is present within a string. Even though the text I am looking for is clearly there, my code seems to ignore it and goes straight to the else part of the statement. Here is the snippet of code causing th ...

How can the value of a button be displayed in an input box using an onclick function?

When the button '1' is clicked, it displays the value "1" inside a <!p> tag. However, the second button '2' does not display the value "2" in the input box. Even though both functions are identical. //Function with working func ...

The behavior of JavaScript replace varies between Chrome and IE

This JavaScript code successfully replaces a string in Chrome: myUrl = someUrl.replace('%2C%7B%22itn%22%3A%5B%22%20guidelines%20%22%5D%7D', ''); However, when tested in Internet Explorer, it does not replace the string as expected. T ...

The interaction between a JavaScript function call and C# is not functioning properly

Attempting to invoke the JavaScript function from CodeBehind ( C# ) : function scrollToBottom() { window.scrollTo(0, document.body.scrollHeight); } The function successfully executes when directly called from my asp.net application. However, ...

Introducing the World of Wordpress Blogging

How can I create an introduction on my WordPress site similar to the one found at ? I am specifically interested in incorporating the expanding horizon line effect. It seems like it may just be a GIF that plays and then fades into the homepage. Are there ...

Tips for displaying two input decorations in Material UI beside one another within a text field

In the Text Field demonstration, I noticed input adornments at the start and end. However, I am looking to have two input adornments at the end specifically. I attempted to add them using endAdornment: {InputAdornment InputAdornment}, but encountered an er ...

Executing a controller action in Yii by utilizing JavaScript's $.get method

Recently, I've been attempting to invoke a controller action using javascript $.get. A helpful member on Stack Overflow recommended the following code: $.get("custom/balance", function(){ }); In this code snippet, 'custom' is the control ...

Utilizing a dynamic form action connected to an Express route

I've been grappling with creating an HTML form in my nodejs application that directs to the appropriate express route upon submission. After researching online, I stumbled upon a potential solution as outlined below: <script> $('#controlPa ...

Content is not properly fitting in the Bootstrap modal window

I am experiencing difficulties with the appearance of a bootstrap modal on my website. Specifically, the modal div seems to be too tall and too narrow in comparison to the modal-dialog div. Here is where I am triggering the modal. <footer> < ...