Adjust the quantity of images shown in the Flex Slider carousel

My website includes a flex slider with a carousel, but it seems that I did not configure the properties of the slider correctly (or it could be a CSS issue) as shown here: . The last image in the carousel is only partially visible.

While I am able to click on it, ideally I would like it to look like this: , with next/previous buttons always visible and displaying 4 full images. The 5th image should be on the next slide.

Below is the HTML code:

<div class="slider">
    <div class="flexslider" id="slider">
    <ul class="slides">
        <li><img src="image1.jpg" /></li>
        <li><img src="image2.jpg" /></li>
        <li><img src="image3.jpg" /></li>
        <li><img src="image4.jpg" /></li>
        <li><img src="image5.jpg" /></li>
    </ul>
    </div>
    <!--flexslider-->
    <div class="flexslider" id="carousel">
    <ul class="slides">
        <li><img src="image1.jpg" /></li>
        <li><img src="image2.jpg" /></li>
        <li><img src="image3.jpg" /></li>
        <li><img src="image4.jpg" /></li>
        <li><img src="image5.jpg" /></li>
    </ul>
    </div>
    <!--flexslider-->
    </div>

The jQuery code used is:

$('.flexslider').each(function() {
                var $root = $(this);

                // Remove item if no image is found
                $root.find("li").each(function(){
                    var src = $(this).find("img").attr("src");
                    if(!src){
                        $(this).remove();
                    }
                });
                });
                $('#carousel').flexslider({
                    animation: "slide",
                    controlNav: false,
                    animationLoop: false,
                    slideshow: false,
                    itemWidth: 91,
                    itemMargin: 19,  
                    asNavFor: '#slider',
                    minItems: 4
                  });

                  $('#slider').flexslider({
                    animation: "slide",
                    controlNav: false,
                    animationLoop: false,
                    slideshow: false,
                    sync: "#carousel"
                  });


        }

I have created a demo page for reference:

Any suggestions? Cheers.

Answer №1

Your carousel arrows are going out of bounds and the image is being cut off because you are overwriting the flexslider css. A little background on flexslider => itemwd refers to the width of the li element, not the image itself. Itemmargin is the margin set by the user in the css and should be considered when sliding. So, if your image is 91px wide and the margin for each side of the li is set to 10px, then the itemwd should be 91+10+10=111. Make sure to set these values in screen.css

#carousel .flex-viewport img {width:91px;}
#carousel .flex-viewport li{
margin:1px 5px 1px 5px;
/*these margins are the ones mentioned in itemMargin in the js*/
}

If you want the arrows to show outside the carousel, remove the overflow hidden property. @screen.css

#carousel.flexslider {
height: 65px; 
border:0;
box-shadow:none;
border-radius:0;
/*overflow:hidden;*/ /*remove this to display arrows next/prev*/
margin-left:0;margin-right:0;
}

And you are already doing these...

#carousel .flex-direction-nav .flex-prev { left: 0 !important; opacity: 1 !important; 
margin-left:-30px; } /*this 30 px represents the width of next/prev*/


#carousel .flex-direction-nav .flex-next { right: 0 !important;  
opacity: 1 !important; margin-right:-30px;} /*this 30 px represents the width of next/prev*/

Make these changes at the JS level...

$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
itemWidth: 111,
itemMargin: 10,  
asNavFor: '#slider'                    
});

See working demonstration

Answer №2

Are you aware of the dimensions of the container element containing the thumbnails? If so, you can easily fix the width of the thumbnails accordingly.

For example, if the container for the thumbnails is 600px wide,

$('.slideshow').slideshow({
  thumbnailWidth: 150,
  thumbnailMargin: 10,
});

this setup will ensure that only four complete thumbnails are displayed at a time.

Answer №3

Setting the width of the navigation bar:

Using CSS

 #slider .flex-next, #slider .flex-prev{
    display:none;
 }
 #carousel .flex-viewport{
    margin: 0 40px;
 }

Here is an example of the implementation: http://jsfiddle.net/47rf6/1/

Additionally, in the JavaScript section

$('.flexslider').flexslider({
  itemWidth: 99,
  itemMargin: 19,
});

Calculation to determine the size:Parent Element = 472px Therefore Thumbnail's = (width: 99 + margin = 19px) * 4(number of thumbnails to display) = 472px.

If you wish to position the arrows inside the thumbnail div - follow these instructions:

The example provided may not include margins. However, the concept should be clear. Please note that images may not be evenly divided and the flexslider may not be responsive. There are other carousel options available that may better suit your needs without extensive customization required. You have the option to customize it further if needed by analyzing your specific code. Please ensure all thumbnails are of equal size for consistency.

Answer №4

Given that the width of your slider div is 472px, these are the settings you should use:

$('#carousel').flexslider({
   animation: "slide",
   controlNav: false,
   animationLoop: false,
   slideshow: false,
   itemWidth: 91, 
   itemMargin: 29,  //adjust this value to 29px for your case
   asNavFor: '#slid2r',
   minItems: 4
});

If your itemWidth is set to 91, then the itemMargin should be 29px in order to display only four thumbnails with the fifth one appearing on the next slide.

To achieve this in CSS, utilize the following:
#carousel .flex-viewport li{ margin-right:29px; }

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

FitText.js malfunctioning

I'm currently experimenting with using FitText.js to dynamically adjust the size of headlines to fit within the limits of the browser width. Interestingly, while this script successfully resizes the text in multiple sections of my website, it seems t ...

How can I customize the color of Chrome's default date and time picker to a different shade of blue?

Is there a way to customize the color of the blue buttons, text, and date indicator in the native datetime picker for Chrome using CSS? https://i.stack.imgur.com/eZSaE.png ...

Following the modification of the Context root, the JSP page is no longer functioning as expected

Recently, I developed a JSP page within the webapp that utilizes jquery, CSS, and Angular JS. The files jquery-1.12.0.js, angular.min.js, and TableCSSCode.css are all located in the same directory as the JSP page. Initially, my application context was set ...

Bring google map markers to life with animation

Is there a way to create an animation like the one shown in this example? I'd like for the map to highlight the corresponding place when a user clicks or hovers over a location in the list. How can I make this happen? I've tried searching on Go ...

Chrome browser experiencing a disappearing vertical scroll bar issue on a Bootstrap Tab

<div class="tabs-wrap left relative nomargin" id="tabs"> <ul class="nav ultab" id="fram"> <li class="active"><a href="#history" data-toggle="tab" id="history1" >History< ...

How to highlight text within an iframe using the mouse and displaying the selected text in a separate div

I'm currently able to select text with the mouse and display that selection in a div. However, I'm struggling to do the same thing when dealing with an iframe displaying a page on the same domain. Despite trying various solutions found here, I h ...

Display the background-image of the <body> element only when the image has finished loading

I have a webpage where I want to delay showing a large image until it has finished downloading. Instead, I would like to display a background with a fading effect while the image loads. The challenge is that the background image must be set within the bod ...

I am having trouble with my jQuery wrap function and it is not functioning correctly

I'm having trouble with implementing the jQuery wrap function. (function ($) { $.fn.customWrap = function () { applyWrapper(this); return this; }; function applyWrapper($element) { var $input = $('<input&g ...

Is it possible to nest a parsys within another parsys in this context?

On my webpage, I have a paragraph system (parsys) with a component that contains two inner paragraph systems. When I try to add a rich text component to each of these inner paragraph systems, the components overlap and become uneditable. Is it possible t ...

Revamping the Create form in MVC based on selected options and storing the data in the database dynamically

I am facing a challenge with my models - Post, Car, Category, and SubCategory. Car inherits from Post and has additional attributes. Post includes fields for CategoryID and SubCategoryID. I want to create a dynamic view that allows users to save cars as we ...

Delete entries in table based on user-provided criteria

Hello there, I'm new to this community and seeking some assistance. I am currently learning jQuery/Javascript and have encountered a problem that has me stumped. The issue arises with a table where rows are generated based on a user-selected number f ...

Preventing ReactJS tooltips from exceeding the boundaries of the screen

Here is a simple demo showcasing blocks with tooltips that appear when hovered over. However, there seems to be an issue with the functionality. The tooltip should ideally be displayed either from the left or right side of the block. To determine the size ...

"Adjusting the Height of an MUI Autocomplete Input Field: A Simple Guide

I've been attempting to shrink the size of the Input field in MUI autocomplete but haven't had any luck. Here's the code I tried: styling: autocompleteStyle: { height: '2.3rem', color: `${theme.palette.grayDark1} !important ...

Increased impact of dynamically added elements following page transition

After implementing dynamic functionality from jQuery in my code, I encountered an issue where if I navigate back one page and then return to the original page containing the added elements, they seem to trigger twice upon clicking. To troubleshoot, I incl ...

Retrieving data from a <div> element within an HTML string using jQuery and AJAX

Having trouble extracting a value from a div within an HTML string. Seeking assistance in identifying the issue. I've attempted various methods to retrieve the data, but none seem to work for me. It appears I may be overlooking something crucial. $( ...

What is the best way to align an image underneath text?

I'm currently working on this design concept: https://i.stack.imgur.com/wJm0t.png Below the title, there is a particle image with half square images positioned on the top right and bottom left corners. My goal is to center the particle image below th ...

Yii: Implementing a dynamic ID update for AJAX functionality in CGridView

I am currently working with Yii 1.1 to create a master-detail order-order-details grid. Here is what I have achieved so far: When I click on the detail icon (left icon), it uses ajax to load the detail grid with the order details. To achieve this, I used a ...

Capturing information within a jQuery function by accessing data from another function

Can data be collected from another function while the function is running? // Custom Function function getData(){ var name = 'tom'; return name } // Main Target Area $('.myDiv').click(function(){ // I need to retrieve dat ...

What is the best way to retrieve an item from an object?

Consider the following scenario: const myUl = $("<ul>"); $("<li>").appendTo(my_ul); $("<li>").appendTo(my_ul); $("<li>").appendTo(my_ul); $("<li>").appendTo(my_ul); How can we access the last li element in the ul? ...

Tips for correctly loading all elements on an HTML page before making CSS modifications

This question has been asked several times in the past. I am asking because when I used the on ready callback in jQuery, it did not change the placeholder text of my element "search_input". $( document ).ready(function() { $("#search_input").attr(' ...