diff --git a/js/carousel.js b/js/carousel.js index ab622f6490..d0492b2dba 100644 --- a/js/carousel.js +++ b/js/carousel.js @@ -34,8 +34,8 @@ // Options - var setCarouselHeight = function() { - var firstImage = view.find('.carousel-item img').first(); + var setCarouselHeight = function(imageOnly) { + var firstImage = view.find('.carousel-item.active img').first(); if (firstImage.length) { if (firstImage.prop('complete')) { view.css('height', firstImage.height()); @@ -44,8 +44,8 @@ view.css('height', $(this).height()); }); } - } else { - var imageHeight = view.find('.carousel-item').first().height(); + } else if (!imageOnly) { + var imageHeight = view.find('.carousel-item.active').first().height(); view.css('height', imageHeight); } }; @@ -445,17 +445,21 @@ }); - $(window).off('resize.carousel-'+uniqueNamespace).on('resize.carousel-'+uniqueNamespace, function() { + var throttledResize = Materialize.throttle(function() { if (options.fullWidth) { item_width = view.find('.carousel-item').first().innerWidth(); - item_height = view.find('.carousel-item').first().innerHeight(); + var imageHeight = view.find('.carousel-item.active').height(); dim = item_width * 2 + options.padding; offset = center * 2 * item_width; target = offset; + setCarouselHeight(true); } else { scroll(); } - }); + }, 200); + $(window) + .off('resize.carousel-'+uniqueNamespace) + .on('resize.carousel-'+uniqueNamespace, throttledResize); setupEvents(); scroll(offset); diff --git a/sass/components/_carousel.scss b/sass/components/_carousel.scss index cc05804c55..506f6c80d6 100644 --- a/sass/components/_carousel.scss +++ b/sass/components/_carousel.scss @@ -2,7 +2,6 @@ &.carousel-slider { top: 0; left: 0; - height: 0; .carousel-fixed-item { &.with-indicators {