【问题标题】:How to create circular image gallery如何创建圆形图片库
【发布时间】:2017-08-03 14:48:58
【问题描述】:

我必须将客户徽标排列成圆圈,如图所示,我已经尝试过,但是 没有得到完美的圆,有没有可用的模板?

【问题讨论】:

标签: javascript html css


【解决方案1】:

这样的?

要计算圆上的点,您可以使用:

var x = Math.cos(point) * size;
var y = Math.sin(point) * size; 

然后就像我在下面所做的那样循环输入值,或者只是手动计算圆圈中的点并将它们硬编码。

function getCircle(offset, size, point, circlesize) {
  var x = Math.cos(point) * size;
  var y = Math.sin(point) * size; 
  var $div = $('<div class="picturediv"></div>');
  var $wrap = $('<div class="wrap"></div>');
  $wrap.css({
    top: offset + 'px',
    left: offset + 'px'
  });
  
  
  $div.css({
    top: (size+x) + 'px',
    left: (size+y) + 'px',
    width: circlesize + 'px',
    height: circlesize + 'px'
  });
  $wrap.append($div);
  $('#wrap').append($wrap)
}

for(var c=0;c<6;c++) {
   getCircle(200, 100,c * 45,50);
}
for(var c=0;c<=10;c++) {
   getCircle(100, 200,c * 25.7, 75);
}
.picturediv {
   width: 50px;
   height: 50px;
   background-color:black;
   border: 1px solid red;
   border-radius:50%;
   position: absolute;
   top: 0px;
   left: 0px;
   background-image: url(https://i.imgur.com/AilIzSF.jpg);
   background-position: -219px -193px;;
   background-repeat: no-repeat;
   
}
.wrap {
  position: relative;
  left: 0px;
  left: 0px;
}
#wrap {
   width:100%;
   height: 100%;
   background-color: gray;
   position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrap">
  <div class="wrap">
    <div class="picturediv" style="width:120px;height:120px;left:265px;top:265px;"></div>
  </div>
</div>

【讨论】:

  • 谢谢,让我试试这个,
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-24
  • 2021-06-30
  • 2016-06-11
相关资源
最近更新 更多