Bootstrap 3: Using img-circle, how to get circle from non-square image?

前端 未结 8 1616
生来不讨喜
生来不讨喜 2021-01-31 16:16

I have rectangular, not necessarily square images.

Using Bootstrap\'s img-circle, I\'d like to get circular crops, <

8条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 16:42

    the problem mainly is because the width have to be == to the height, and in the case of bs, the height is set to auto so here is a fix for that in js instead

    function img_circle() {
        $('.img-circle').each(function() {
            $w = $(this).width();
            $(this).height($w);
        });
    }
    
    $(document).ready(function() {
        img_circle();
    });
    
    $(window).resize(function() {
        img_circle();
    });
    

提交回复
热议问题