3

我试图找出 Flexslider 的一个问题,该问题仅在我在 Safari Mobile 等移动浏览器上测试时出现。

所有 <li> 容器的高度都与最高的 <li> 相同,即使没有足够的内容证明使它们具有相同的高度也是如此。

我不确定如何截取它的屏幕截图,因为它在桌面浏览器上运行良好,但在移动浏览器上却不行。这是一个小提琴,当我在桌面浏览器上查看它时,它显示了它的工作方式,容器的高度根据内容的数量调整大小。

http://jsfiddle.net/CsCyh/

这是hml:

<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>

这是 flexslider 的 JS:

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

5 回答 5

3

嗯,我前段时间遇到过这个问题。我希望这有帮助!

var evenSliderHeight = function(slideContainer, slideItem) {
  var slider_height = 0;
  var $slider_slide = $(slideContainer).find(slideItem);
  $slider_slide.each(function() {
    var __height = $(this).outerHeight(true);
    if ( slider_height < __height ) {
       slider_height = __height;
    }
  });
  $slider_slide.css('min-height', slider_height);
};
evenSliderHeight('.flexslider-container', '.slide');
于 2013-10-17T20:52:22.987 回答
2
$('.flexslider').flexslider({
  after: function(slider){
    currHeight = $('.flexslider').find('.slides > li').eq(slider.currentSlide).outerHeight(true);
    $('.flexslider').height(currHeight);
  }
});

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


于 2014-01-31T23:12:40.213 回答
2

For anyone still has this issue in 2019/2020, please have a look at the new property called "smoothHeight" at the Flexslider docs

I fixed my issue by setting "smoothHeight" to true.

$('.sliders').flexslider({
    animation: 'slide',
    smoothHeight: true,
    controlNav: false,
    customDirectionNav: $('.js-slider-control button'),
});
于 2020-01-21T21:27:28.650 回答
1

Here is a CSS only solution. This is tested 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; }

The !important overrides the display:block; property that flexslider generates as inline style. Now all panels share an equal height, based on the highest slide.

于 2020-04-14T06:55:57.120 回答
0

Add this to the script that calls the slider.

animateHeight: false,

eg.:

$(window).load(function(){ if ( $('#content-slider-wrap').length == 0 ) return false
    $('#content-slider-wrap').flexslider({
        animation:"fade",
        slideshow: true,
        directionNav: true,
        animateHeight: false,
        controlNav:false ,
........... etc etc
于 2017-10-05T11:45:13.853 回答