Using jQuery to adjust a parent element's height to match it's visible child's height

前端 未结 3 2008
盖世英雄少女心
盖世英雄少女心 2021-01-28 03:18

I\'ve got a slideshow running in a container and need the height of the container to match the visible slide\'s height. Unfortunately the images are absolutely positioned and th

3条回答
  •  爱一瞬间的悲伤
    2021-01-28 03:44

    Instead of running before or after the slideshows callback, this scales the image as the window resizes. Perfect!

    $(window).resize(function() {
        $('#main').css('height',$('img.slide:visible').height());
    });
    

提交回复
热议问题