Tips for avoiding image overlap in a multi-carousel display

I am facing an issue with a bootstrap4 multi-carousel where the images are overlapping each other, taking up the entire screen width one by one.

My implementation includes HTML, CSS, and JS files.

<div class="row">
       <div class="MultiCarousel" data-items="1,3,5,6" data-slide="1"            id="MultiCarousel"  data-interval="1000">
        <div class="MultiCarousel-inner">
            <div class="item">
                <div class="pad15 pad">
                    <img src="files/products_02.jpg" alt="ball">
                    <p class="lead">Loreum Ipsum Loreum</p>
                    <p>₹ 6000</p>
                </div>
            </div>
            <div class="item">
                <div class="pad15">
                        <img src="files/products_03.gif" alt="ball">
                        <p class="lead">Loreum Ipsum Loreum</p>
                        <p>₹ 6000</p>
                    </div>
            </div>
            <div class="item">
                <div class="pad15">
                        <img src="files/products_04.gif" alt="ball">
                        <p class="lead">Loreum Ipsum Loreum</p>
                        <p>₹ 6000</p>
                    </div>
            </div>
            <div class="item">
                <div class="pad15">
                        <img src="files/products_05.gif" alt="ball">
                        <p class="lead">Loreum Ipsum Loreum</p>
                        <p>₹ 6000</p>
                    </div>
            </div>
            <div class="item">
                <div class="pad15">
                        <img src="bat4.jpeg" alt="ball">
                        <p class="lead">Loreum Ipsum Loreum</p>
                        <p>₹ 6000</p>
                    </div>
            </div>
            <div class="item">
                <div class="pad15">
                        <img src="ball1.jpeg" alt="ball">
                        <p class="lead">Loreum Ipsum Loreum</p>
                        <p>₹ 6000</p>
                    </div>
            </div>
        </div>
        <button class="btn btn-primary leftLst"><</button>
        <button class="btn btn-primary rightLst">></button>
    </div>
</div>

CSS:

.MultiCarousel { float: left; overflow: hidden; padding: 15px;   width: 100%; position:relative; }
.MultiCarousel .MultiCarousel-inner { transition: 1s ease all; float: left; }
.MultiCarousel .MultiCarousel-inner .item { float: left;}
.MultiCarousel .MultiCarousel-inner .item > div { text-align: center; padding:10px; margin:10px; background:#f1f1f1; color:#666;}
.MultiCarousel .leftLst, .MultiCarousel .rightLst { position:absolute; border-radius:50%;top:calc(50% - 20px); }
.MultiCarousel .leftLst { left:0; }
.MultiCarousel .rightLst { right:0; }

.MultiCarousel .leftLst.over, .MultiCarousel .rightLst.over { pointer-events: none; background:#ccc; }

JS:

$(document).ready(function () {
var itemsMainDiv = ('.MultiCarousel');
var itemsDiv = ('.MultiCarousel-inner');
var itemWidth = "";

$('.leftLst, .rightLst').click(function () {
var condition = $(this).hasClass("leftLst");
if (condition)
click(0, this);
else
click(1, this)
});

ResCarouselSize();

$(window).resize(function () {
ResCarouselSize();
});

//this function define the size of the items
function ResCarouselSize() {
var incno = 0;
var dataItems = ("data-items");
var itemClass = ('.item');
var id = 0;
var btnParentSb = '';
var itemsSplit = '';
var sampwidth = $(itemsMainDiv).width();
var bodyWidth = $('body').width();
$(itemsDiv).each(function () {
id = id + 1;
var itemNumbers = $(this).find(itemClass).length;
btnParentSb = $(this).parent().attr(dataItems);
itemsSplit = btnParentSb.split(',');
$(this).parent().attr("id", "MultiCarousel" + id);

if (bodyWidth >= 1200) {
incno = itemsSplit[3];
itemWidth = sampwidth / incno;
}
else if (bodyWidth >= 992) {
incno = itemsSplit[2];
itemWidth = sampwidth / incno;
}
else if (bodyWidth >= 768) {
incno = itemsSplit[1];
itemWidth = sampwidth / incno;
}
else {
incno = itemsSplit[0];
itemWidth = sampwidth / incno;
}
$(this).css({ 'transform': 'translateX(0px)', 'width': itemWidth * itemNumbers });
$(this).find(itemClass).each(function () {
$(this).outerWidth(itemWidth);
});

$(".leftLst").addClass("over");
$(".rightLst").removeClass("over");

});
}


//this function used to move the items
function ResCarousel(e, el, s) {
var leftBtn = ('.leftLst');
var rightBtn = ('.rightLst');
var translateXval = '';
var divStyle = $(el + ' ' + itemsDiv).css('transform');
var values = divStyle.match(/-?[\d\.]+/g);
var xds = Math.abs(values[4]);
if (e == 0) {
translateXval = parseInt(xds) - parseInt(itemWidth * s);
$(el + ' ' + rightBtn).removeClass("over");

if (translateXval <= itemWidth / 2) {
translateXval = 0;
$(el + ' ' + leftBtn).addClass("over");
}
}
else if (e == 1) {
var itemsCondition = $(el).find(itemsDiv).width() - $(el).width();
translateXval = parseInt(xds) + parseInt(itemWidth * s);
$(el + ' ' + leftBtn).removeClass("over");

if (translateXval >= itemsCondition - itemWidth / 2) {
translateXval = itemsCondition;
$(el + ' ' + rightBtn).addClass("over");
}
}
$(el + ' ' + itemsDiv).css('transform', 'translateX(' + -translateXval + 'px)');
}

//It is used to get some elements from btn
function click(ell, ee) {
var Parent = "#" + $(ee).parent().attr("id");
var slide = $(Parent).attr("data-slide");
ResCarousel(ell, Parent, slide);
}

});

I want to ensure that the images maintain their original dimensions or adjust responsively. Additionally, I only want four images displayed at a time, with the ability to view the rest using the arrow buttons. Currently, all six images are visible simultaneously.

Answer №1

try implementing the CSS below in your project. Hopefully, it will come in handy.

.MultiCarousel .MultiCarousel-inner .item > div{overflow:hidden}
img { max-width:100%; }

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

Tips for directing to access a directory in RShiny

I'm trying to figure out how to use an actionButton to link to open a folder in a new tab within my shiny app. I attempted to achieve this by using the "file:" tag, but it seems that the folder only opens if the user right-clicks on the actionButton ...

What is the process to set a Woocommerce checkout field as optional when a checkbox is marked?

I need assistance with customizing the checkout page on Wordpress Woocommerce. Specifically, I want to make the field 'billing_name' not required if the checkbox 'buy_on_company' is checked. Currently, I have successfully hidden ' ...

Netlify Alert: Build process ended with an error code: 254

Appreciate your assistance. I have a basic HTML file that I intended to host through Netlify. In my Git repository, I have three files - index.html, style.css, and a readme file. The structure of the HTML file is as follows: <!DOCTYPE html> < ...

Removing a row with a button click in PHP PDO (with Pagination) and MySQL database

I'm having trouble with the Delete button in my code. When I click on it, nothing happens and the record is not deleted. I have tried a few solutions but still can't figure out what's wrong. Any help would be greatly appreciated. // This ...

Expanding the `div` element to visually occupy the entire vertical space

I'm facing a design challenge with my webpage layout. I have a fixed header and footer, but I need the content section to dynamically adjust its height between the two. The goal is to fill the remaining vertical space with a background-image in the co ...

Ways to adjust the size of an HTML paragraph tag

I'm currently involved in working on an HTML/JS application that is similar to PowerPoint. This application allows users to create slides and display them on screens of various sizes (such as a screen with dimensions of 128x90 pixels or 2x1 meters). ...

The issue encountered with Bootstrap Carousel and the <img> tag displaying incorrect object-fit and object-position properties

Currently, I am working on a carousel design that looks like the code snippet below: <div id="myCarousel" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> ... </ol> <div class="carousel ...

Exploring jQuery: Choosing all li elements starting from a specific index to the end

Is there a way to select the last item, li:eq('+(lastItemIndex)+')', and all subsequent items until the end? Check out this JSFiddle demo for an example of changing elements in li from 3 onwards. ...

Scrolling horizontally to display dynamic columns based on a search query in AngularJS

I am facing a challenge with implementing search functionality in a table that has multiple dynamic columns with a horizontal scrollbar. The goal is for users to be able to search for a specific column name or data, and if a match is found, the scrollbar s ...

What could be causing the animation: fill property to malfunction in CSS (SVG)?

My SVG code has an ID called "logo" <svg id= "logo" width="918" height="114" viewBox="0 0 918 114" fill="none" xmlns="http://www.w3.org/2000/svg"> <mask id="path-1-outside-1" ...

What is the best way to ensure that only one of two textboxes is filled out in an HTML form?

Looking to create 2 fields that are mutually exclusive. One will be a FileField and the other a TextBoxField. Is there an HTML form template available for this specific scenario? I've scoured the web but haven't come across one yet. Apologies ...

Strange occurrences within the realm of javascript animations

The slider works smoothly up until slide 20 and then it suddenly starts cycling through all the slides again before landing on the correct one. Any insights into why this is happening would be greatly appreciated. This issue is occurring with the wp-coda- ...

Printing a JSON array in Angular: A step-by-step guide

Take a look at this Stackblitz example https://stackblitz.com/edit/angular-parse-object Response format received from REST API is [{"id":123,"name":Test,"value":{"pass": true, "verified": true}}, {"id":435,"name":Test12,"value":{"pass": false, "verified" ...

There seems to be an issue with the CSS file linking properly within an Express application

Every time I run my app.js file, the index.html file is displayed. However, when I inspect the page, I notice that the CSS changes are not taking effect. Strangely, if I open the HTML file using a live server, the CSS changes are visible. Can someone exp ...

Creating a dropdown in HTML that overlaps another div requires using relative and absolute positioning

Having created a navigation bar with dropdown menu items that reveal on hover, I encountered an issue. Below the navigation bar lies a slideshow of images. Whenever I hover over the dropdowns, the slideshow div obstructs the view, making it impossible to s ...

How can I generate an Xpath for the given element?

I am trying to find the Xpath for the specific name (I1888 - Child 1.1) without using the contains function. Currently, I am using the following xpath: "//span[contains(@class,'TreeTitleRed')][contains(.,'Child 1.1')]", but I would like ...

What is the best way to adjust the width of the <span> element in an Angular application?

This snippet showcases a piece of HTML code. <div class="col-md-8"> <span class="label">Product Name</span> <span> <mat-form-field> <input matInput formControlName="productName"> </mat-form ...

Leveraging bootstrap4-toggle along with localStorage to switch between CSS styles for dark mode

I'm having trouble getting localStorage to work with Bootstrap 4 and the bootstrap4-toggle library from https://github.com/gitbrent/bootstrap4-toggle in order to implement a CSS dark mode toggle. The issue I'm facing is that the class dark is no ...

Tips on ensuring a div automatically adjusts its size to accommodate collapsed elements

I can't seem to find the article about this, so I'm not sure if it's been asked before. Currently using Bootstrap 4.3.1. I have a div with collapsed elements inside. Whenever I expand or collapse these elements, the div adjusts its size (n ...

Is it possible for you to generate an array containing only one element?

I've encountered an issue with my code. It functions correctly when the JSON data for "Customers" is in array form. However, if there is only one customer present, the code erroneously creates 11 table columns (corresponding to the number of keys in t ...