I\'m trying to make a navigation-div with 4 buttons, one to go left, one to go right, another one to go down and yet another one to go up. Plus there needs to be an OK-butto
The old version is below, it resizes using jQuery. But after looking at this question: SVG polygon points with percentage units support, you can achieve the same effect by applying percentages and without needing any JS:
See it working here: http://jsfiddle.net/th4uo8wk/4/
Old answer:
Oops, by the time I had it ready, Paulie_D had come with the answer.
Well, here you have a responsive one (you can see it working on this jsfiddle, resize the screen to see it working responsively):
HTML:
JS/JQUERY
function resizeButtons() {
// get the width
var w = $("#mySVG").width();
// make it squared
$("#mySVG").height(w);
// recalculate the position of each polygon
$("#ok").attr("points", w * 0.25 + "," + w * 0.25 + " " + w * 0.75 + "," + w * 0.25 + " " + w * 0.75 + "," + w * 0.75 + " " + w * 0.25 + "," + w * 0.75);
$("#up").attr("points", "0,0 " + w + ",0 " + w * 0.75 + "," + w * 0.25 + " " + w * 0.25 + "," + w * 0.25);
$("#left").attr("points", w + ",0 " + w + "," + w + " " + w * 0.75 + "," + w * 0.75 + " " + w * 0.75 + "," + w * 0.25);
$("#down").attr("points", "0," + w + " " + w * 0.25 + "," + w * 0.75 + " " + w * 0.75 + "," + w * 0.75 + " " + w + "," + w);
$("#right").attr("points", "0,0 " + w * 0.25 + "," + w * 0.25 + " " + w * 0.25 + "," + w * 0.75 + " 0," + w);
}
CSS
svg { background:#ccc; }
#ok { fill: red; }
#up { fill: blue; }
#down { fill: green; }
#right { fill: yellow; }
#left { fill: orange; }