Thursday, June 9, 2016

Make Boostrap columns equal in height using JQuery

I faced issue when we displaying photo gallery, some images are bigger in height and other are small in height, to resolve issue i found out below solution to equalize Bootstrap columns so all images looks same in height

Even when you resize or view in smaller device it will automatically resize Bootstrap columns height


 <script type="text/javascript">
        function equalizeHeight() {
            var row = $('.equalize');
            $.each(row, function () {
                var maxh = 0;
                $.each($(this).find('> div[class^="col-"]'), function () {
                    $(this).css("height", "");
                });
            });
            $.each(row, function () {
                var maxh = 0;
                $.each($(this).find('> div[class^="col-"]'), function () {
                    if ($(this).height() > maxh)
                        maxh = $(this).height();
                });
                $.each($(this).find('> div[class^="col-"]'), function () {
                    $(this).height(maxh);
                });
            });
        }
        $(window).resize(function () {
            equalizeHeight();
        });

        $(document).ready(function () {
            equalizeHeight();
        });
    </script>

No comments:

Post a Comment