Variety of image widths displayed in bxslider

I am currently facing a challenge while using the bxslider with images of varying sizes that I want to have the same height but different widths. My goal is to create a carousel similar to the ones shown in the examples on . While these examples work well, my images are 300, 400, and 500 pixels wide, each with unique heights scaled to a standard height of 400px. I do not wish to alter the image's width or crop it. How can I effectively utilize bxslider with images of various widths?

If bxslider cannot accommodate this requirement, is there an existing jquery plugin that offers this functionality?

For reference, you can view an example at: http://jsfiddle.net/GdD52/2/

<ul class="slider1">
    <li class="slide"><img src="http://placehold.it/140x130&text=FooBar1"/></li>
    <li class="slide"><img src="http://placehold.it/150x115&text=FooBar2"/></li>
    <li class="slide"><img src="http://placehold.it/130x160&text=FooBar3"/></li>
    <li class="slide"><img src="http://placehold.it/145x142&text=FooBar4"/></li>
</ul>

Answer №1

#bx-wrapper img {
    width: auto !important
}

However, I am encountering difficulties with touch scrolling. As a solution, I will experiment with using owlCarousel.

Answer №2

Being a fan of web galleries, I decided to create a script for an infinite scrolling gallery with images of varying widths: Fiddle
I understand that you wanted to change the Gallery bxslider, but this solution seems viable.
In my opinion, the bxslider Gallery does not offer this functionality.
You can see in my fiddle that there is a gallery with images of different widths.
This script is just a demonstration and can be enhanced. If you like my answer, I will enhance it further.

<script type="text/javascript>
$(document).ready(function(){
    var wid=0;
    var maskWidth=0;
    var arr=[];
    $('#images img').each(function(i){
        wid+=parseInt($(this).attr('data-width'));
        arr.push($(this).attr('data-width'));
        if(i<3){maskWidth+=parseInt($(this).attr('data-width'));}
    });
    // Setting container width = 3 times the width of the largest image
    var biggest = Math.max.apply( null, arr )*3;
    $('#container').css('width',biggest+'px');
    // Setting mask width = sum of width of first 3 images
    $('#mask').css({'width':(maskWidth+36)+'px'});
    // Setting images width = total width of all images
    $('#images').css({'width':wid+'px'});
    // Setting attribute data-last on third image
    $('#images img:eq(2)').attr('data-pos','last');

    // Next and previous clicks are handled differently based on the position of the image div
    $('.next').click(function(e){
        e.preventDefault();
        var widthx=$('#mask').width();
        var next=parseInt($('#images').find('img[data-pos="last"]').next('img').attr('data-width'))+12;
        // Remaining code for incrementing gallery content goes here...
    });

    $('.prev').click(function(e){
        e.preventDefault();
        // Code for navigating back in gallery goes here...
    });
});
</script>

If you're interested, check out another improved version of this gallery in this FIDDLE, where you'll find buttons for browsing images in groups of three.
Once again, there is room for improvement. Some possible next steps include:
N1 - Making the gallery responsive
N2 - Transforming the script into a jQuery plugin

Answer №3

Here's a simple code snippet I put together - check it out on this FIDDLE link.

This code is just a starting point, so please let me know what modifications you'd like to see. It's not flawless as one of the images may appear too wide, but that can be easily adjusted based on your requirements. Essentially, most of the styling is done in CSS with the images floated within each div.

JavaScript Section:


var first, second, third;

var numPhotos = $('.hidden img').length;

if (numPhotos === 0) {
    first = 0; second = 0; third = 0;
}
if (numPhotos === 1) {
    first = 0; second = 1; third = 0;
    displayImages(first, second, third);
}
if (numPhotos === 2) {
    first = 0; second = 1; third = 2;
    displayImages(first, second, third);
}
if (numPhotos > 2) {
    first = 0; second = 1; third = 2;
    displayImages(first, second, third);
}

$('.forward').on('click', function(){
    first += 1;
    second += 1;
    third += 1;
    displayImages(first, second, third);
    
    if(third == numPhotos) {
        first = 1; second = 2; third = 3;
        displayImages(first, second, third);
    }
});

function displayImages(first, second, third) {
    $( '.minishowme:nth-child(1)' ).html('');
    $( '.minishowme:nth-child(2)' ).html('');
    $( '.minishowme:nth-child(3)' ).html('');

    $('.hidden img:nth-child(' + first + ')').clone().appendTo( '.minishowme:nth-child(1)' );
    $('.hidden img:nth-child(' + second + ')').clone().appendTo( '.minishowme:nth-child(2)' );
    $('.hidden img:nth-child(' + third + ')').clone().appendTo( '.minishowme:nth-child(3)' );
}

Answer №4

I want a carousel similar to the ones shown on the website

http://bxslider.com/examples/carousel-demystified
. These examples are working well...

The current example does not align the slides in the center. Instead, it displays 3 slides aligned to the top left corner.

If you want to display images with different heights and widths, it is recommended to align them at the same width.

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

How can I adjust two overlapping divs for proper display?

It seems like I have two divs overlapping on the same line. The layout appears fine on a PC but not on an iPad or mobile device. Can someone please review the code and point out any mistakes I might have made? The issue is with the content overlapping the ...

Angular Material floating labels vanishing or being truncated when hovered over

The behavior of floating labels seems to be causing issues for me. When I hover over them, the label either disappears completely, gets cut off at the bottom, or at times even at the top. I've tried adjusting z-index and overflow visibility within the ...

Issues with the responsiveness of Bootstrap 4.5.0 grid system

While following a Django tutorial, I encountered an issue with Bootstrap cards and CSS styling. Using the latest version (Bootstrap 4.5.0), I noticed that my responsive grid was causing the cards to overlap as I increased the screen size. Comparing it to t ...

Looking to modify the parsing of JSON data based on a specific string value - is this achievable?

At the moment, I am utilizing jQuery to parse a JSON object and display the values in a table. In this table, I have set the beginning of the URL as static and then concatenated a value to it. However, the issue arises when the specific string's value ...

Increase a variable within a looping structure using jQuery

I am faced with a task that involves selecting two values from different dropdown lists, such as 1001 from the first dropdown and 1003 from the second. Upon clicking the 'add' button, I need to pass these selected values, along with the values in ...

Showcase data entries using jQuery data tables

My goal is to retrieve data from a database and present it in data tables using PHP, but currently, when I execute this PHP code on a browser, it only displays the records in a basic table format. I am aiming for a more interactive solution by implementing ...

Encountering an "unsupported media type" error while using jquery ajax with json in Spring MVC

I am currently working on a Spring MVC application and I am facing an issue in my JSP where I need to pass an object to the controller and then receive the object back in the JSP. Unfortunately, I am encountering an error message saying "Unsupported media ...

How can I convert the stylesheet link from fonts.google.com into a CSS class and include it in my file.css as an internal style instead of an external one?

Looking to incorporate a font from fonts.google.com? Here's how you can do it: <link rel="preconnect" href="https://fonts.gstatic.com"> <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@200;300 ...

Node containing clickable buttons

TL;DR - Can we implement functional links within a jsTree node without resorting to JavaScript redirection? I am interested in incorporating buttons inside a jsTree node, like so: This was my initial attempt: $('#tree').jstree({ &apos ...

What are the steps to employ a query string to display a specific image?

If I understand correctly, I can utilize a query string and parse it to display certain information. How would I apply that concept to load a specific image? https://codepen.io/anon/pen/qYXexG <div id="gallery"> <div id="panel"> <img ...

What is the best way to conceal a preloader using jQuery?

How can I hide the ajax preloader on specific pages in my code? Any suggestions would be appreciated. Here is the code snippet: <script language="javascript" type="text/javascript"> $(window).load(function() { //alert("Loader-->"+n[1]) ...

Jumping transitions in thumbnail images

Could you please visit I've noticed that when hovering over the thumbnails in the last column, the images jump a bit after transition, especially in Firefox. Do you have any suggestions on how to resolve this issue? ...

What could be causing my website's screen resolution to not fit properly on mobile devices?

Initially, the resolution perfectly matched the width of mobile devices. However, after changing the background image, for some reason, the width no longer fits the device length precisely. I've tried resetting to a point where the resolution was fine ...

Retrieving a designated value from a jquery object sent via an ajax call

Currently, I have a setup where clicking on a link sends the link's ID via AJAX to a coldfusion page for querying and returning an object. The jquery function in use is: $(".thelink").click(function(){ var link_id = $(this).attr("id"); var ...

Having trouble with Jquery not applying or removing the selected class in the navigation menu

My website is built using PHP, with the index file dynamically loading pages from a folder named "pages." Additionally, I have the navigation menu stored in a separate file. I am attempting to highlight the text color when a link is clicked, but I am faci ...

Conditionals in ng-class Syntax

I'm attempting to apply a class conditionally to an element, but I'm struggling with the correct syntax. I've experimented with the code below, but it's not functioning as expected: ng-class="{foo: bar === "true"}" The value of bar i ...

AJAX request in jQuery version 1.4.4 and above will convert an empty array or object into a string

My JavaScript object is causing issues when trying to AJAX POST to a PHP script. While it used to work fine in jQuery 1.4.1, versions 1.4.4 and above now convert empty arrays or objects into strings like "0", which is not the desired behavior. JS: $(docu ...

Showing a tooltip in Angular when a button is disabled

<button [disabled]="(!dataConceptSummmaryFlag || dataConceptSummmaryFlag === false) && (!selectedLOBFlag || selectedLOBFlag === false) && (!adsListFlag || adsListFlag === false)" class="lmn-btn lmn-btn-primary" ...

Choosing a combination of classes

For my web application, I created checkboxes that control the visibility of windows by toggling classes on elements. My JavaScript code successfully achieves this functionality. $(document).ready(function(){ $('#field').change(function(){ ...

Issues arise when the sub-menu does not function properly and overlaps with other elements of

I've been working with a client on their website and encountered an issue. On the mobile version of our menu, when I hover over a menu item that has several sub-menu items, those items display properly, but there is an element below them showing thro ...