in Education by
Basically I've managed to layout my DIV elements into a circle shape but I've not managed to work out how to calculate the deg of rotation need to have them face OUTWARD from the center of the circle. $(document).ready(function(){ var elems = document.getElementsByClassName('test_box'); var increase = Math.PI * 2 / elems.length; var x = 0, y = 0, angle = 0; for (var i = 0; i < elems.length; i++) { var elem = elems[i]; // modify to change the radius and position of a circle x = 400 * Math.cos(angle) + 700; y = 400 * Math.sin(angle) + 700; elem.style.position = 'absolute'; elem.style.left = x + 'px'; elem.style.top = y + 'px'; //need to work this part out var rot = 45; elem.style['-moz-transform'] = "rotate("+rot+"deg)"; elem.style.MozTransform = "rotate("+rot+"deg)"; elem.style['-webkit-transform'] = "rotate("+rot+"deg)"; elem.style['-o-transform'] = "rotate("+rot+"deg)"; elem.style['-ms-transform'] = "rotate("+rot+"deg)"; angle += increase; console.log(angle); } }); does anyone have to knowledge on how I can do this. Cheers -C JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Note that rot depends on angle, except angle is in radians. DRY, so either convert from angle to rot: // The -90 (degrees) makes the text face outwards. var rot = angle * 180 / Math.PI - 90; Or just use angle when setting the style (but use radians as a unit), and drop rot's declaration: // The -0.5*Math.PI (radians) makes the text face outwards. elem.style.MozTransform = "rotate("+(angle-0.5*Math.PI)+"rad)";

Related questions

0 votes
    Basically I've managed to layout my DIV elements into a circle shape but I've not managed to work ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Basically I've managed to layout my DIV elements into a circle shape but I've not managed to work ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    i have a website that contain an iframe. www.vendeposto.com.br and i want to hide an element Im trying to do this ... the vendeposto.com.br site is this: Postos de gasolina a venda...
asked May 1, 2022 in Education by JackTerrance
0 votes
    i have a website that contain an iframe. www.vendeposto.com.br and i want to hide an element Im trying to do this ... the vendeposto.com.br site is this: Postos de gasolina a venda...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    i have a website that contain an iframe. www.vendeposto.com.br and i want to hide an element Im trying to do this ... the vendeposto.com.br site is this: Postos de gasolina a venda...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    This is part of the component : import MyComp from '../../lib/MyComp' const Data = ( { data } ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    This is part of the component : import MyComp from '../../lib/MyComp' const Data = ( { data } ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    Course Results (${courseResponseList.getCourses().size()}) Want to show above div. jquery script. jQuery. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Course Results (${courseResponseList.getCourses().size()}) Want to show above div. jquery script. jQuery. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    Hello I have a problem witz hiding div. Here is an example (try it only in Chrome) http:// ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    Write a program to read name of 10 student from keyboard and arrange them alphabetically. Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    Take from a pack of cards all the Aces, Kings, Queens and Jacks. Arrange them in a 4 × 4 square so that every ... and one card of each suit (Heart, Spade, Diamond, Club)....
asked Feb 11, 2021 in Education by JackTerrance
0 votes
    I gave this CSS class to some input fields .searchField { display: inline-block; } This is their ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
...