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

Requesting data from an ASP.NET MVC web API using an Ajax call

I have been working on an MVC app and trying to establish an AJAX connection to a web API controller. However, the error message that keeps appearing is "Unidentified". Additionally, when I attempt to throw a random exception in my api controller delete ac ...

How to filter jQuery DataTables by column using comparison operators

Recently, I've been utilizing the amazing DataTables jQuery plugin along with the filter plug in. But now, I find myself pondering if there's a way to filter table columns by row using a comparison operator (such as '<', '>&a ...

What could possibly be causing my code to execute multiple times?

Within my code, I have the following function that is triggered when the document is ready: $('#file_upload_form').submit(function(){ // show loader [optional line] //if(document.getElementById('upload_frame') == ...

Encountering an issue with Google distance matrix where property 'text' is undefined

Below is a snippet of code that calculates the distance between two user-provided addresses. This code currently runs when the user submits a form in this manner: $("#distance_form").submit(function (e) { e.preventDefault(); calculateDistance(); }); ...

"Discover the step-by-step process of transforming an input field value into a checkbox with

I've been experimenting with creating a To-Do list using HTML, CSS, and Javascript. I've managed to capture the input field value in a fieldset so far. However, my goal is to find a way to transform the input field value from the textfield into a ...

Clear a variable that was sent through the post method in an ajax call

Within my JavaScript file, I have the following Ajax code: // Default settings for Ajax requests $.ajaxSetup({ type: 'POST', url: path + '/relay.php' + '?curr=' + currency + "&ver=" + Ma ...

Try using the doubletap event instead of dblclick in jquery mobile, although it seems to be ineffective on iPad devices

Is there a way to fix the issue with jQuery Mobile doubletap option not working on iPad and instead only zooming the page? Thank you for your help. $("#book div img").live('doubletap', function() { $("#book").turn("disable", true); ...

"Creating a new element caused the inline-block display to malfunction

Can someone explain why the createElement function is not maintaining inline-block whitespace between elements? Example problem First rectangle shows normal html string concatenation: var htmlString = '<div class='inline-block'...>&l ...

"Discover a unique online platform showcasing videos and images with a creative

I recently updated my personal website to showcase some of the tools I've developed through short looping videos. Initially, everything was working well with just images, but when I switched to videos, I encountered some unexpected behaviors. Interest ...

Assistance in configuring Zurb Foundation 5 for optimal integration with Laravel

As a relatively new user to Laravel with previous experience using older versions of Foundation, I am currently in the process of setting up a new Laravel project. My goal is to integrate the Foundation framework into my project, but I find myself a bit co ...

How can I center a text element vertically within its parent div element?

After researching various solutions to align text within a div, I have found that many recommend using the vertical-align property. Despite trying this method, it does not seem to work for my specific case. .free { display: inline-block; -webkit-bor ...

Dynamic CSS sizing

Currently, I am in the process of creating a component and my goal is to achieve a specific layout without the use of JavaScript, preferably utilizing flexbox. Essentially, envision a messenger chat screen with a header and footer containing controls. htt ...

Function returning undefined when accessing prototype property in JavaScript

When attempting to create an image rotator using prototypal inheritance, I am encountering an error in the console showing: TypeError: this.curPhoto is undefined this.curPhoto.removeClass('previous'); I have placed this code in the callb ...

When you set the href attribute, you are essentially changing the destination of the link

UPDATE: I'm not referring to the status bar; instead, I'm talking about the clickable text that leads to a link. /UPDATE I've gone through a few similar posts but couldn't find a solution. I have a link that needs to be displayed. www ...

Setting the current date of a jQuery datepicker to the value of an input tag

I am looking to assign a value to an input tag that has a datepicker attached to it. Upon initialization of the datepicker, I want to set this value. Below is a hypothetical example of what I am trying to achieve: HTML: <input id="test" value="">&l ...

Disregard any labels when it comes to clickable areas for mouse events

Here is a simple example in JSFiddle where a text is displayed over an image inside a div element. Depending on where the cursor hovers, it can exhibit three different behaviors: pointing hand over the image, allowing text selection over the content of the ...

Removing a background by linking a CSS file

Issue Resolved: I have found the solution. The problem was that the css document still contained html tags. Thank you to everyone who provided assistance. While designing a website using css, I encountered a situation where the site worked perfectly when ...

Display only the labels of percentages that exceed 5% on the pie chart using Chart JS

I'm currently diving into web development along with learning Chart.js and pie charts. In my project, the pie chart I've created displays smaller percentage values that are hardly visible, resulting in a poor user experience on our website. How c ...

Obtain the current activity

In my code, I have a wrapper div that contains another div. When the inner div is clicked, a message should be displayed. However, the issue arises when the inner divs all share a common class despite having unique IDs generated at runtime. My markup is g ...

Guide on integrating an HTML and CSS register form in Django

I have successfully created a responsive register and login using HTML and CSS. Instead of utilizing the standard register form and login provided by Django upon configuration, I want to apply my own custom template. To summarize, while I am familiar with ...