iBrazilian2
iBrazilian2

Reputation: 2293

How to recalculate css with jQuery window resize?

I'm currently trying to recalculate the height of the li during window resize/scrolling inwards or outwards, but for some reason when the page loads it will no longer re-calculate the height and set the ul to it's child height.

This is the code that I wrote to check the height and set the height to it's parent.

  var ulHeight = $(".carousel__slider li").outerHeight();
  $( window ).resize(function() {
        $(".carousel__slider > ul").height(ulHeight);
  });
  $(window).trigger('resize');

How can I make jQuery resize recalculate the height on window resize? I've created the exact exemple that I'm using on my site now.

https://jsfiddle.net/va5hpL0r/5/

Upvotes: 1

Views: 272

Answers (1)

Nandhu
Nandhu

Reputation: 339

 $( window ).resize(function() {
        ulHeight = $(".carousel__slider li").outerHeight();
        $(".carousel__slider > ul").height(ulHeight);
  });

calculate height on resizing https://jsfiddle.net/dnL0neux/

Upvotes: 2

Related Questions