Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:22:24+00:00 2026-06-01T21:22:24+00:00

I am creating a circular menu in Javascript and have decided to use a

  • 0

I am creating a circular menu in Javascript and have decided to use a combination of absolute positioning and -webkit-transforms to position the list items around the outside of a circle.

Here is a demo that has been hacked into shape for a JSFiddle: http://jsfiddle.net/5XnKZ/6/

You can see that the placement of the list items is loosely circular, but they don’t appear in order or with the equal widths between that I was expecting. If you experiment with adding and removing the items from the list you will see that different numbers of list items have vastly different effects on how they are displayed.

I am positioning the items in the center of the circle with absolute positioning, then translating them into their positions on the circle with webkit transforms. The x and y for the transforms are obtained like this:

var x = Math.cos(d) * r;
var y = Math.sin(d) * r;

Where d is the angle in radians that the item should be at, and r is the radius of the circle I am positioning them on.

Can anyone see what is going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:22:26+00:00Added an answer on June 1, 2026 at 9:22 pm

    Your index was not calculated right.

    (function() {
        //A foreach alternative function
        var each = function(a, b) {
            for (var i = 0; i < a.length; i++) {
                b(a[i]);
            }
        };
    
        //Get an array of all the circlr elements
        var circles = document.getElementsByClassName('circle');
        //Iterate over these elements
        each(circles, function(circle) {
            //For each of their children
            var i = 0;
            each(circle.children, function(child) {
                //Get child's index as a percentage of 2 PI radian
                var p = (i) / circle.children.length * (2*Math.PI);
                var r = 80;
                child.style.webkitTransform = 'translatey(' + Math.sin(p) * r + 'px) translatex(' + Math.cos(p) * r + 'px)';
                i++;
            });
        });
    })();
    

    Check the corrected JsFiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking at creating a circular menu and so far, I can
I'm currently creating a circular doubly-linked list as exercise. The exercise is templating the
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a server-side socket will fail if I'm trying to use the same port
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I'm creating a sql select query for an access database, and receiving a circular
I'm creating a whiteboard application using SVG in HTML5, and javascript to manipulate the
I'm using the 'TPCircularBuffer' class for creating a circular buffer object, from this website
I'm creating Django application, with forum-like thingy. One of the views should display list
I am creating test cases and I need to cover circular dependencies. So far

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.