Ensure that the height of all Flexslider <li> elements are consistent with the tallest <li> element on a mobile browser

Having an issue with Flexslider that only shows up when testing on a mobile browser like Safari Mobile.

The <li> containers are all matching the height of the tallest one, even if there isn't enough content to justify equal heights.

Not sure how to capture a screenshot since it works fine on desktop but not on mobile. Check out this fiddle where it behaves as expected on my desktop browser, resizing based on content amount:

http://jsfiddle.net/CsCyh/

Here is the HTML code:

<div class="flexslider">
  <ul class="slides">
    <li>
      <img src="http://i.imgur.com/YSVlz2Z.jpg" />
      <h2><a href"#">First Link Here</a></h2>
      <p>Some text here that could be a message</p>
      <a href="#" data-role="button" data-icon="arrow-r" data-iconpos="right">Another Link Here</a>
    </li>
    <li>
      <img src="http://i.imgur.com/YSVlz2Z.jpg" />
      <h2><a href"#">Second Link Here</a></h2>
      <p>Some text here that could be a message</p>      
    </li>
    <li>
     <img src="http://i.imgur.com/YSVlz2Z.jpg" />
     <h2><a href"#">Third Link Here</a></h2>
     <p>Some text here that could be a message</p>     
    </li>
  </ul>
</div>

And here's the JS for flexslider:

$('.flexslider').flexslider();

Answer №1

Oh, I remember dealing with this issue some time back. Hopefully, this solution works for you!

function adjustSliderHeight(sliderContainer, sliderItem) {
  var sliderHeight = 0;
  var $sliderItems = $(sliderContainer).find(sliderItem);
  $sliderItems.each(function() {
    var itemHeight = $(this).outerHeight(true);
    if (sliderHeight < itemHeight) {
       sliderHeight = itemHeight;
    }
  });
  $sliderItems.css('min-height', sliderHeight);
};
adjustSliderHeight('.flexslider-container', '.slide');

Answer №2

$('.flexslider').flexslider({
  after: function(slider){
    currentH = $('.flexslider').find('.slides > li').eq(slider.currentSlide).outerHeight(true);
    $('.flexslider').height(currentH);
  }
});

JSFiddle Update: http://jsfiddle.net/CsCyh/14/


Answer №3

If you are still experiencing this problem in the years 2019/2020, I recommend checking out the latest feature called "smoothHeight" in the Flexslider documentation

My issue was resolved by enabling the "smoothHeight" option.

$('.sliders').flexslider({
    animation: 'slide',
    smoothHeight: true,
    controlNav: false,
    customDirectionNav: $('.js-slider-control button'),
});

Answer №4

If you're looking for a CSS-only solution, this code snippet is specifically tailored for the animation: "slide" property:

.flexslider .flex-viewport { display: flex; flex-direction: column; }
.flexslider .flex-viewport > ul { display: flex; }
.flexslider .flex-viewport > ul > li { display: flex !important; }

By using the !important declaration, it ensures that the display:block; style generated by flexslider is overridden. As a result, all panels will now have equal heights based on the tallest slide.

Answer №5

Make sure to include the following code snippet in your slider script:

animateHeight: false,

For example:

$(window).load(function(){ if ( $('#slider-content').length == 0 ) return false
    $('#slider-content').flexslider({
        animation:"fade",
        slideshow: true,
        directionNav: true,
        animateHeight: false,
        controlNav:false ,
........... and so on

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

Retrieve information from a controller and pass it to a Component in AngularJs

Having an issue with passing data from a controller to a component in AngularJs. The data is successfully passed to the template component, but it shows up as undefined in the controller! See below for my code snippets. The controller angular.module(&a ...

Arranging multiple selections in Dojo's dijit

Just wondering if there's a built-in way in Dojo/Dijit multiselect to sort the options, or do I have to manually implement it? Many thanks Edit: I managed to solve my issue by implementing a sorting algorithm. Here's the code for anyone who mi ...

It is recommended that the page does not scroll while utilizing both the sidenav and toolbar simultaneously in Angular Material

Using md-sidenav without md-toolbar works fine. The sidenav opens correctly, as shown in the image below. https://i.sstatic.net/PjsPp.png However, when a toolbar is added before the sidenav or its containing section, opening the sidenav causes the page t ...

Submission error occurs if file upload is absent

When attempting to submit a form with a file, I encounter issues if the selected file for upload is changed (e.g. renamed) before submitting the form. The form fails to submit. Below is an example of my code: <form action="test.htm" method="post" encty ...

Tips for making multiple files accessible in an npm package?

I have developed an npm package called example-package. Typically, users would import it like this: import RootModule from "example-package"; However, I also have a file nested within the package structure. Package Root > src > Feature > inde ...

Code to execute function depending on the width of a div

Looking for a script that can run a function depending on the width of a div. I want the ability to trigger the function when the div is resized. For example, if the div's width is 300px, execute function 1; if it's 700px, execute another functi ...

Stylize the div within the hyperlink when hovering over it

I am trying to add a hover effect to a div inside a hyperlink using CSS, but I'm not sure how to do it. The divs in question have background images set in the CSS. <div class="header_menu"> <div class="foa_logo"><img src="images/FOA ...

unable to establish a connection to SQL in [PHP]

I'm having an issue with my code and need some help fixing it. The website is supposed to allow users to add, edit, and delete data. However, when I fill out the fields and click "add", it redirects me to a blank page. Here's the code that I have ...

Tips for Maintaining White Space and Line Breaks in Django

Currently, I am working on a project where I aim to showcase a user's code. My approach involves utilizing Django's forms. However, upon submitting the form, the whitespace and line breaks do not seem to be preserved in the output. I would great ...

Unlocking the Power of Dynamic Title Text in Your Content

Recently, I came across a tooltip code on Stack Overflow which I have been using. The issue I am facing is that the text in the title section is hardcoded and I need to customize it for different labels. How can I modify the code to make it flexible enough ...

What modifications can be made to this jQuery code to ensure that the toggle is initially open on screen sizes larger than 992px?

Looking to make some changes to this code so that the toggle is expanded by default on screens larger than 992px, while remaining collapsible. On smaller screens, it should be collapsed by default. jQuery(document).ready(function($) { $("a.search-tri ...

Error message in Ember JS: "#<error>" is uncaught within the {{#each}} statement

Whenever I run a specific route on my ember app, an 'Uncaught #error" message appears in my console. Despite not affecting the functionality of the code and seemingly working flawlessly, I can't help but wonder why it's there. After some inv ...

Guide to integrating HTML templates with Vue.js

I am experimenting with using vue.js but encountered some issues when trying to integrate it with a purchased template. I have included all the necessary .css and .js files in my index.html file and then called the components within vue.js itself. index.h ...

An array of length x containing keys of JavaScript objects

I'm currently working on a generator for chartjs to help me with creating datasets. My approach involves using object keys to extract data from each element in an array. Each element in the array may contain nested objects like this: https://i.ssta ...

Implementing CSS class on HTML tags with JavaScript in WordPress

Currently, I am customizing a WordPress theme and I am looking to include an additional class to an element without removing any existing classes. In this particular theme, there is a designated spot for adding JavaScript code within the theme options. B ...

What is the best way to retrieve Moralis roles using React?

Today is my first time exploring Moralis. I watched some tutorials and went through the documentation. Right now, I am attempting to query the Roles (_Role) but I keep getting an empty array as a result. const { fetch: getStaffRole } = useMoralisQuery(&apo ...

Challenge with decrypting data using Mysql's AES_ENCRYPT and client-side Javascript Aes.Ctr.decrypt

The issue at hand I have confidential data stored in a MySQL database, and I am looking to encrypt this data when performing a SELECT query. Subsequently, I aim to decrypt it on the client-side using JavaScript. Here is an example: MySQL SELECT query: ...

Submitting identical named elements in MVC4 can be achieved by utilizing the proper syntax and techniques

I have two elements with the same name. One is created before dynamically and the other after being created dynamically. Element created before dynamically - <input id="txtamt" name="Amount[]" type="text" ></td> Element created after dynami ...

How to toggle specific elements with Jquery's slideToggle() function

On my page, I have a section with questions that have hidden answers beneath them. When a user clicks on a question, the answer smoothly slides down (thanks to a separate function). Clicking on the question again hides the answer once more. The issue I&ap ...

Initialization of an empty array in Typescript

My promises array is structured as follows: export type PromisesArray = [ Promise<IApplicant> | null, Promise<ICampaign | ICampaignLight> | null, Promise<IApplication[]> | null, Promise<IComment[]> | null, Promise<{ st ...