Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ana's response is kick ass! That's some serious CSS-fu. </p> <p>My solution may not be quite what you are hoping for, but it's another possible solution. I'm working on a compass interface right now that has a similar style of arc shaped buttons. I decided to develop it using <a href="http://raphaeljs.com/" rel="noreferrer">Raphael</a> and SVG. </p> <p>I created an arc shape in Illustrator, exported the SVG for it, grabbed the path definition for the arc from the exported SVG file, and used Raphael to build my interface with it. </p> <h2><a href="http://jsfiddle.net/elliotlarson/jUTFm/" rel="noreferrer">Here's a JSFiddle of it</a>.</h2> <p>Here's the JavaScript:</p> <pre><code>var arc = { fill: '#333', stroke: '#333', path: 'M53.286,44.333L69.081,7.904C48.084-1.199,23.615-2.294,0.648,6.78l14.59,36.928C28.008,38.662,41.612,39.27,53.286,44.333z' }; var paper = Raphael(document.getElementById("notepad"), 500, 500); var arcDegrees = 45; var centerX = 210; var centerY = 210; var compassRadius = 68; var currentlyActive = 45; var directions = [ {label:'N', degrees:0, rotatedDegrees:270}, {label:'NE', degrees:45, rotatedDegrees:315}, {label:'E', degrees:90, rotatedDegrees:0}, {label:'SE', degrees:135, rotatedDegrees:45}, {label:'S', degrees:180, rotatedDegrees:90}, {label:'SW', degrees:225, rotatedDegrees:135}, {label:'W', degrees:270, rotatedDegrees:180}, {label:'NW', degrees:315, rotatedDegrees:225} ]; function arcClicked() { var label = $(this).data('direction-label'); $("#activeArc").attr('id', null); $(this).attr('id', 'activeArc'); } for (i = 0; i &lt; 360; i += arcDegrees) { var direction = _.find(directions, function(d) { return d.rotatedDegrees == i; }); var radians = i * (Math.PI / 180); var x = centerX + Math.cos(radians) * compassRadius; var y = centerY + Math.sin(radians) * compassRadius; var newArc = paper.path(arc.path); // newArc.translate(x, y); // newArc.rotate(i + 89); newArc.transform('T' + x + ',' + y + 'r' + (i + 89)); if (direction.degrees == currentlyActive) { $(newArc.node).attr('id', 'activeArc'); } $(newArc.node) .attr('class', 'arc') .data('direction-label', direction.label) .on('click', arcClicked); } </code></pre> <p>Here's the related CSS:</p> <pre><code>#notepad { background: #f7f7f7; width: 500px; height: 500px; } .arc { fill: #999; stroke: #888; cursor: pointer; } .arc:hover { fill: #777; stroke: #666; } #activeArc { fill: #F18B21 !important; stroke: #b86a19 !important; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload