javascript - Absolutely Position Element Around a Circle -
I have some HTML below with embedded SVG
& lt; Section id = "deck-head" & gt; & Lt; Svg xmlns = "http://www.w3.org/2000/svg" width = "250" height = "250" & gt; & Lt; Ch & gt; & Lt; Title & gt; Marker & lt; / Title & gt; & Lt; G id = "marker-frame" & gt; & Lt; Path across = "white" D = "M 133.300003,64.800003l0, -33.500004 L-16.100006,0 l0.3339999 9C-30.799995,3.700005-53.499996,29.599998-53.499996,60.800003c0,33.900002 27.600002,61.299995 61.299999,61.299995C61 300003, -27.399994 61.300003, -61.299995c0, -30.900002 -23.600006, -56.599998 -53, -60.599998zm-53.5606099997c0, -24.900002 20.299995, -45.199997 45.199997, -45.199997 S 45.199997,20.299995 45.199997,45.199997s-20.199997, 45.300003 -45.199997,45.300003-45.199997, -20.400009 -45.199997, -45.300003z "/> & Lt; / G> & Lt; / G> & Lt; / Svg & gt; & Lt; Marks & gt; 90 & amp; nbsp; Degree; & Lt; / Marks & gt; & Lt; / Section & gt;
I should be able to replicate the following layouts without using an external JavaScript library
ignore red
I managed to rotate SVG in the right direction Am - though I'm having trouble, this element is taking the whole situation from the tick / tip of the pink circle, depending on which direction The Umta.
In my head the argument was that I had the following lines with: get circle center point get rotation left & amp; The above situation will be based on the top above.
However, I have been completely lost that to get the top and left coordinates, that calculation will be completely lost, where it can create the position of the place where it should be.
These are just simple polar coordinates. JQuery is not needed, just for easy manipulations
var angle = 0, center = 125, radius = 110, pi = monastery. PI; Set Intrvol (function () {angle + = 1; $ ( '# C'). Atrr ( 'transform', 'Rotate (' + + ', 125, 125)); // calculate new coordinates for Mark xx = center + radius * Gnitkos (angle * pi / 180 - PI / 2); var y = center + radius * math. (angle * P / 180 - PI / 2); $ ( '# M'). css ( {Top: y + 'pixels', left: x + 'pixels'});}, 100); body {background-color: black;} #m {position: absolute;} section {poisition:
& lt; Script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Section id = "deck-head" & gt; & Lt; Svg xmlns = "http://www.w3.org/2000/svg" width = "250" height = "250" & gt; & Lt; Ch & gt; & Lt; Title & gt; Marker & lt; / Title & gt; & Lt; G id = "marker-frame" & gt; & Lt; Path fill = "white" id = "c" d = "m133.300003,64.800003l0, -33.500004l-16.100006,0l0,33.299999c-30.799995,3.700005 -53.499996,29.599998 -53.499996,60.800003c0,33.900002 27.6, 00,002, 61.299995 61.299999,61.299995s61.300003, -27.399994, 61.300003, -61.299995c0, -30.900002 -23.600006, -56.599998 -53, -60.599998zm-53.5606099997 C, -24.900002 20.299995, -45.199997 45.199 997, -45.199997s45 .199997,20.299995 45.199997,45.199997 -20.199997,45.300003 -45.199997,45.300003-45.199 997, -20.400009 -45.199 997, -45.300003z "/ & gt; & Lt; / G> & Lt; / G> & Lt; / Svg & gt; & Lt; Icon id = 'm' & gt; 90 & amp; nbsp; Deg; & Lt; / Symbol & gt; & Lt; / Section & gt;
Comments
Post a Comment