carouFredSel responsive height

前端 未结 14 835
一整个雨季
一整个雨季 2021-01-30 11:46

i am having height problems of my responsive carousel using carouFredSel.

since the images are responsive and the carousel is also set to responsive.

It still ad

14条回答
  •  甜味超标
    2021-01-30 12:34

    No hacks, this is using the custom events in 6.2.1. After creating the slider(s) for the page, setup a window resize handler, and within that for each slider get the new height and use the 'configuration' event to reset the height of that slider. Finally trigger the 'updateSizes' event. The relevant code:

    var options = {
      responsive: true,
      height: 'auto',
      onCreate: function() { jQuery(window).on('resize', resizeMyslider); },
      // remaining options
      ...
    };
    myslider.carouFredSel(options);
    
    function resizeMyslider(e) {
      var newHeight = 0;
      // Get new height of items (be sure css isn't setting a fixed height)
      myslider.children().map(
        function() {
          newHeight = Math.max(newHeight, jQuery(this).height());
        }
      );
      // Change configuration of slider
      myslider.trigger('configuration', ['height', newHeight + 'px']);
      // Tell slider to use new configuration height
      myslider.trigger('updateSizes');
    }
    

    Ideally you'd implement the window resize event through a timeout or requestanimationframe, but this is the basics.

提交回复
热议问题