Recently fiddled over this question on stackoverflow:
Dynamically arrange elements around circle
But this solutions includes jquery, and $(this) keywords. I want to convert this code:
function distributeFields(deg) {
deg = deg || 0;
var radius = 200;
var fields = $('.field'), container = $('#container'),
width = container.width(), height = container.height(),
angle = deg || Math.PI*3.5, step = (2*Math.PI) / fields.length;
fields.each(function() {
var x = Math.round(width/2 + radius * Math.cos(angle) - $(this).width()/2);
var y = Math.round(height/2 + radius * Math.sin(angle) - $(this).height()/2);
if(window.console) {
console.log($(this).text(), x, y);
}
$(this).css({
left: x + 'px',
top: y + 'px'
});
angle += step;
});
}
this is what i tried to do before getting stuck at ($this) keyword:
function distributeFieldsJS(deg){
deg = deg || 0;
let radius = 200;
let fields = document.querySelectorAll('.field'),
container = document.querySelector('#container'),
width = container.width(), height = container.height(),
angle = deg || Math.PI * 3.5,
step = (2*Math.PI) / fields.length;
})