[英]how to get a circle by setting equal width and height
need to set height
of an element equal to its width
需要将元素的
height
设置为其width
ie - to get a perfect circle即 - 得到一个完美的圆圈
here is the try and console shows equal values but the resulting height
is obviously much higher then the width
这是尝试和控制台显示相等的值,但结果
height
显然比width
高得多
$('button').on('click', function(){ let box = $('#box'); let w = box.width(); console.log(w); box.height(w); let h = box.height(); console.log(h); });
.box{background:orange; width:30%; border-radius:50%; overflow:hidden;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button>CLICK</button> <br><br> <div class='box' id='box'> lorem ipsum<br> lorem ipsum<br> lorem ipsum<br> lorem ipsum<br> lorem ipsum<br> </div> <br><br>
You could get the of width
and height
and assign to ot the minimum of both.您可以获得
width
和height
并分配给两者中的最小值。
$('button').on('click', function(){ let box = $('#box'); let l = Math.min(box.width(), box.height()); box.height(l); box.width(l); });
.box{background:orange; width:30%; border-radius:50%; overflow:hidden;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button>CLICK</button> <br><br> <div class='box' id='box'> lorem ipsum<br> lorem ipsum<br> lorem ipsum<br> lorem ipsum<br> lorem ipsum<br> </div> <br><br>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.