liveBook · Manning

Radial menu

As explained in Math for Web Design

A radial menu is a user interface menu whose items are arranged around a central point.

A radial menu arranges items around a central point. Trigonometry turns each item's angle and radius into CSS coordinates, creating an evenly spaced circular layout. section 1.4.8

Six items around a 70px radius

With a center at (100px, 100px), six 40px items, and a 70px radius, item 0 uses angle 0. Its position is x = 100 + 70 × cos(0) − 20 = 150 and y = 100 + 70 × sin(0) − 20 = 80. section 1.4.8

const items = document.querySelectorAll('.menu-item');    #1
items.forEach((item, i) => {    #2
    const angle = (2 * Math.PI / totalItems) * i;    #3
    const x = centerX + radius * Math.cos(angle) - 20;    #4
    const y = centerY + radius * Math.sin(angle) - 20;    #5
    item.style.left = `${x}px`;    #6
    item.style.top = `${y}px`;    #7
});

The JavaScript listing distributes items by calculating an angle for each index, then assigning sine- and cosine-based left and top coordinates. section 1.4.8

How Math for Web Design covers it

How deep it goes
Works through sine, cosine, radius, angle, center, and item dimensions, stopping at a single positioning example.
Examples
Uses six 40px items around a 70px radius and calculates the first item's coordinates at a 100px center.
What it assumes
Assumes basic JavaScript and CSS while defining sine, cosine, tangent, angles, and right-triangle relationships.
What you can do after
Build it from scratch: calculate circular item positions and assign them through JavaScript.
How it connects
Connects radial menus with trigonometry, sine, cosine, JavaScript, CSS, and circular animation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.